Skip to content

Commit

Permalink
Prevent touch scan on input or text area
Browse files Browse the repository at this point in the history
  • Loading branch information
khaitruong922 committed Sep 24, 2024
1 parent 83d9d80 commit 92aa051
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions ext/js/dom/text-source-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions ext/js/language/text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<import('text-scanner').Events>
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 92aa051

Please sign in to comment.