From f4a987912a3bc7012cbfeaaa35ea94e5f97655e0 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 3 Nov 2019 18:56:22 +0200 Subject: prevent accidental lookup on glossary text select --- ext/fg/js/frontend.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'ext/fg/js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 802221be..84d6af28 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -80,10 +80,7 @@ class Frontend { onMouseMove(e) { this.popupTimerClear(); - if ( - this.pendingLookup || - (e.buttons & 0x1) !== 0x0 // Left mouse button - ) { + if (this.pendingLookup || Frontend.isMouseButton('primary', e)) { return; } @@ -91,7 +88,7 @@ class Frontend { const scanningModifier = scanningOptions.modifier; if (!( Frontend.isScanningModifierPressed(scanningModifier, e) || - (scanningOptions.middleMouse && (e.buttons & 0x4) !== 0x0) // Middle mouse button + (scanningOptions.middleMouse && Frontend.isMouseButton('auxiliary', e)) )) { return; } @@ -498,6 +495,23 @@ class Frontend { default: return false; } } + + static isMouseButton(button, mouseEvent) { + if (['mouseup', 'mousedown', 'click'].includes(mouseEvent.type)) { + switch (button) { + case 'primary': return mouseEvent.button === 0; + case 'secondary': return mouseEvent.button === 2; + case 'auxiliary': return mouseEvent.button === 1; + default: return false; + } + } + switch (button) { + case 'primary': return (mouseEvent.buttons & 0x1) !== 0x0; + case 'secondary': return (mouseEvent.buttons & 0x2) !== 0x0; + case 'auxiliary': return (mouseEvent.buttons & 0x4) !== 0x0; + default: return false; + } + } } Frontend.windowMessageHandlers = { -- cgit v1.2.3