aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/text-scanner.js
diff options
context:
space:
mode:
authorKuuuube <61125188+Kuuuube@users.noreply.github.com>2024-05-14 10:42:05 -0400
committerGitHub <noreply@github.com>2024-05-14 14:42:05 +0000
commitd60b010229cf9031029480b698e87f8b91fbf16f (patch)
tree46065ee1025607da84432c87406a2b5c226398ef /ext/js/language/text-scanner.js
parenta0f92f6fa322436dbf93e8125c8da1954a8a500b (diff)
Cache mousemove and hook keyboard to allow scanning at mouse position while mouse is no longer moving (#917)
Diffstat (limited to 'ext/js/language/text-scanner.js')
-rw-r--r--ext/js/language/text-scanner.js38
1 files changed, 37 insertions, 1 deletions
diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js
index bdbc117e..13db91d5 100644
--- a/ext/js/language/text-scanner.js
+++ b/ext/js/language/text-scanner.js
@@ -88,6 +88,9 @@ export class TextScanner extends EventDispatcher {
/** @type {?import('text-scanner').SelectionRestoreInfo} */
this._selectionRestoreInfo = null;
+ /** @type {MouseEvent | null} */
+ this._lastMouseMove = null;
+
/** @type {boolean} */
this._deepContentScan = false;
/** @type {boolean} */
@@ -546,6 +549,7 @@ export class TextScanner extends EventDispatcher {
*/
_onMouseMove(e) {
this._scanTimerClear();
+ this._lastMouseMove = e;
const inputInfo = this._getMatchingInputGroupFromEvent('mouse', 'mouseMove', e);
if (inputInfo === null) { return; }
@@ -554,6 +558,28 @@ export class TextScanner extends EventDispatcher {
}
/**
+ * @param {KeyboardEvent} e
+ */
+ _onKeyDown(e) {
+ if (this._lastMouseMove !== null && (e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) {
+ const syntheticMouseEvent = new MouseEvent(this._lastMouseMove.type, {
+ screenX: this._lastMouseMove.screenX,
+ screenY: this._lastMouseMove.screenY,
+ clientX: this._lastMouseMove.clientX,
+ clientY: this._lastMouseMove.clientY,
+ ctrlKey: e.ctrlKey,
+ shiftKey: e.shiftKey,
+ altKey: e.altKey,
+ metaKey: e.metaKey,
+ button: this._lastMouseMove.button,
+ buttons: this._lastMouseMove.buttons,
+ relatedTarget: this._lastMouseMove.relatedTarget
+ });
+ this._onMouseMove(syntheticMouseEvent);
+ }
+ }
+
+ /**
* @param {MouseEvent} e
* @returns {boolean|void}
*/
@@ -1050,7 +1076,7 @@ export class TextScanner extends EventDispatcher {
} else if (this._arePointerEventsSupported()) {
eventListenerInfos = this._getPointerEventListeners(capture);
} else {
- eventListenerInfos = this._getMouseEventListeners(capture);
+ eventListenerInfos = [...this._getMouseEventListeners(capture), ...this._getKeyboardEventListeners(capture)];
if (this._touchInputEnabled) {
eventListenerInfos.push(...this._getTouchEventListeners(capture));
}
@@ -1103,6 +1129,16 @@ export class TextScanner extends EventDispatcher {
* @param {boolean} capture
* @returns {import('event-listener-collection').AddEventListenerArgs[]}
*/
+ _getKeyboardEventListeners(capture) {
+ return [
+ [this._node, 'keydown', this._onKeyDown.bind(this), capture]
+ ];
+ }
+
+ /**
+ * @param {boolean} capture
+ * @returns {import('event-listener-collection').AddEventListenerArgs[]}
+ */
_getTouchEventListeners(capture) {
return [
[this._node, 'auxclick', this._onAuxClick.bind(this), capture],