Skip to content

Commit

Permalink
Disallow scanning while mouse is not moving if input, textarea, or ed…
Browse files Browse the repository at this point in the history
…itable elements are active (#958)

* Disallow scanning while mouse is not moving if input, textarea, or editable elements are active

* Move to _inputtingText method
  • Loading branch information
Kuuuube authored and jamesmaa committed May 21, 2024
1 parent 7a4b832 commit df02b95
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ext/js/language/text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}
Expand Down

0 comments on commit df02b95

Please sign in to comment.