From e19204b1ec26a1add25ae47903184dea8e705a33 Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Fri, 17 May 2024 15:10:47 -0400 Subject: Disallow scanning while mouse is not moving if input, textarea, or editable elements are active (#958) * Disallow scanning while mouse is not moving if input, textarea, or editable elements are active * Move to _inputtingText method --- ext/js/language/text-scanner.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index 13db91d5..7c1b5b33 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -562,6 +562,7 @@ export class TextScanner extends EventDispatcher { */ _onKeyDown(e) { if (this._lastMouseMove !== null && (e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) { + if (this._inputtingText()) { return; } const syntheticMouseEvent = new MouseEvent(this._lastMouseMove.type, { screenX: this._lastMouseMove.screenX, screenY: this._lastMouseMove.screenY, @@ -579,6 +580,18 @@ export class TextScanner extends EventDispatcher { } } + /** + * @returns {boolean} + */ + _inputtingText() { + const activeElement = document.activeElement; + if (activeElement && activeElement instanceof HTMLElement) { + if (activeElement.nodeName === 'INPUT' || activeElement.nodeName === 'TEXTAREA') { return true; } + if (activeElement.isContentEditable) { return true; } + } + return false; + } + /** * @param {MouseEvent} e * @returns {boolean|void} -- cgit v1.2.3