Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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