Skip to content

Commit

Permalink
reset original name when alias empty && make alias pastable
Browse files Browse the repository at this point in the history
  • Loading branch information
khaitruong922 committed Jul 26, 2024
1 parent 3a15e06 commit 6603fe3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 8 additions & 3 deletions ext/js/dom/dom-data-binder.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,14 @@ export class DOMDataBinder {
* @param {import('dom-data-binder').ElementObserver<T>} observer
*/
_onObserverChildrenUpdated(element, observer) {
if (observer.hasValue) {
this._setElementValue(element, observer.value);
if (!observer.hasValue) {
return;
}
if (this._isElementContentEditable(element)) {
this._setElementValue(element, element.textContent ?? '');
return;
}
this._setElementValue(element, observer.value);
}

/**
Expand Down Expand Up @@ -292,7 +297,7 @@ export class DOMDataBinder {
*/
_getElementEventType(element) {
if (this._isElementContentEditable(element)) {
return 'focusout';
return 'blur';
}
return 'change';
}
Expand Down
10 changes: 10 additions & 0 deletions ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class DictionaryEntry {
this._outdatedButton.hidden = (version >= 3);
this._priorityInput.dataset.setting = `dictionaries[${index}].priority`;
this._enabledCheckbox.dataset.setting = `dictionaries[${index}].enabled`;
this._eventListeners.addEventListener(this._aliasNode, 'blur', this._onAliasBlur.bind(this), false);
this._eventListeners.addEventListener(this._enabledCheckbox, 'settingChanged', this._onEnabledChanged.bind(this), false);
this._eventListeners.addEventListener(this._menuButton, 'menuOpen', this._onMenuOpen.bind(this), false);
this._eventListeners.addEventListener(this._menuButton, 'menuClose', this._onMenuClose.bind(this), false);
Expand Down Expand Up @@ -180,6 +181,15 @@ class DictionaryEntry {
}
}

/**
*
*/
_onAliasBlur() {
if (!this._aliasNode.textContent) {
this._aliasNode.textContent = this.dictionaryTitle;
}
}

/**
* @param {import('dom-data-binder').SettingChangedEvent} e
*/
Expand Down
2 changes: 1 addition & 1 deletion types/ext/dom-data-binder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type SettingChangedEvent = CustomEvent<SettingChangedEventData>;

export type NormalizedElementType = 'textarea' | 'select' | 'text' | 'checkbox' | 'number' | 'contenteditable' | null;

export type EventType = 'change' | 'focusout'
export type EventType = 'change' | 'blur'

Check failure on line 59 in types/ext/dom-data-binder.d.ts

View workflow job for this annotation

GitHub Actions / Static Analysis

Missing semicolon

export type UpdateTaskValue = {all: boolean};

Expand Down

0 comments on commit 6603fe3

Please sign in to comment.