diff --git a/ext/js/dom/dom-data-binder.js b/ext/js/dom/dom-data-binder.js index 811982a342..ccce7633b3 100644 --- a/ext/js/dom/dom-data-binder.js +++ b/ext/js/dom/dom-data-binder.js @@ -175,18 +175,18 @@ export class DOMDataBinder { const metadata = this._createElementMetadata(element); if (typeof metadata === 'undefined') { return void 0; } const type = this._getNormalizedElementType(element); + const eventType = this._getEventType(element); /** @type {import('dom-data-binder').ElementObserver} */ const observer = { element, type, value: null, hasValue: false, + eventType, onChange: null, metadata, }; observer.onChange = this._onElementChange.bind(this, observer); - - const eventType = type === 'contenteditable' ? 'focusout' : 'change'; element.addEventListener(eventType, observer.onChange, false); void this._updateTasks.enqueue(observer, {all: false}); @@ -200,7 +200,7 @@ export class DOMDataBinder { */ _removeObserver(element, observer) { if (observer.onChange === null) { return; } - element.removeEventListener('change', observer.onChange, false); + element.removeEventListener(observer.eventType, observer.onChange, false); observer.onChange = null; } @@ -285,12 +285,24 @@ export class DOMDataBinder { return null; } + + /** + * @param {Element} element + * @returns {import('dom-data-binder').EventType} + */ + _getEventType(element) { + if (this._isContentEditable(element)) { + return 'focusout'; + } + return 'change'; + } + /** * @param {Element} element * @returns {import('dom-data-binder').NormalizedElementType} */ _getNormalizedElementType(element) { - if (element instanceof HTMLElement && element.isContentEditable) { + if (this._isContentEditable(element)) { return 'contenteditable'; } switch (element.nodeName.toUpperCase()) { @@ -314,4 +326,12 @@ export class DOMDataBinder { } return null; } + + /** + * @param {Element} element + * @returns {boolean} + */ + _isContentEditable(element) { + return element instanceof HTMLElement && element.isContentEditable; + } } diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index 1ddfca54ec..4b5a8ef834 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -1777,7 +1777,7 @@ export class Translator { let score = Number.MIN_SAFE_INTEGER; let dictionaryIndex = Number.MAX_SAFE_INTEGER; let dictionaryPriority = Number.MIN_SAFE_INTEGER; - const dictionaryAlias = ""; + const dictionaryAlias = ''; let maxOriginalTextLength = 0; let isPrimary = false; /** @type {import('dictionary').TermDefinition[]} */ diff --git a/types/ext/dom-data-binder.d.ts b/types/ext/dom-data-binder.d.ts index a58351ff02..3883dd5f1a 100644 --- a/types/ext/dom-data-binder.d.ts +++ b/types/ext/dom-data-binder.d.ts @@ -43,6 +43,7 @@ export type ElementObserver = { type: NormalizedElementType; value: unknown; hasValue: boolean; + eventType: string; onChange: null | (() => void); metadata: T; }; @@ -55,6 +56,8 @@ export type SettingChangedEvent = CustomEvent; export type NormalizedElementType = 'textarea' | 'select' | 'text' | 'checkbox' | 'number' | 'contenteditable' | null; +export type EventType = 'change' | 'focusout' + export type UpdateTaskValue = {all: boolean}; export type AssignTaskValue = {value: ValueType};