From 92aa0510ef4fd48712f263b70d39c2da641dad4e Mon Sep 17 00:00:00 2001 From: Khai Truong Date: Tue, 24 Sep 2024 15:01:02 +0700 Subject: [PATCH] Prevent touch scan on input or text area --- ext/js/dom/text-source-range.js | 11 +++++++++++ ext/js/language/text-scanner.js | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ext/js/dom/text-source-range.js b/ext/js/dom/text-source-range.js index 4450d3284..4bcb59700 100644 --- a/ext/js/dom/text-source-range.js +++ b/ext/js/dom/text-source-range.js @@ -95,6 +95,17 @@ export class TextSourceRange { return this._imposterSourceElement; } + /** + * Determines whether the imposter source element is an input or textarea element. + * @return {boolean} `true` if the imposter source element is an input or textarea element, `false` otherwise. + */ + isImposterInputOrTextArea() { + if (this._imposterSourceElement) { + return this._imposterSourceElement.tagName === 'INPUT' || this._imposterSourceElement.tagName === 'TEXTAREA'; + } + return false; + } + /** * Creates a clone of the instance. * @returns {TextSourceRange} The new clone. diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index f0201b08f..03f7aef55 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -23,6 +23,7 @@ import {log} from '../core/log.js'; import {clone} from '../core/utilities.js'; import {anyNodeMatchesSelector, everyNodeMatchesSelector, getActiveModifiers, getActiveModifiersAndButtons, isPointInSelection} from '../dom/document-util.js'; import {TextSourceElement} from '../dom/text-source-element.js'; +import {TextSourceRange} from '../dom/text-source-range.js'; /** * @augments EventDispatcher @@ -454,8 +455,8 @@ export class TextScanner extends EventDispatcher { async _search(textSource, searchTerms, searchKanji, inputInfo, showEmpty = false) { try { const isAltText = textSource instanceof TextSourceElement; - // Prevent scanning of alt text on touch event - if (isAltText && inputInfo.pointerType === 'touch') { + const isInputOrTextArea = textSource instanceof TextSourceRange && textSource.isImposterInputOrTextArea(); + if (inputInfo.pointerType === 'touch' && (isAltText || isInputOrTextArea)) { return; }