prevent accidental lookup on glossary text select

This commit is contained in:
siikamiika 2019-11-03 18:56:22 +02:00
parent 75ff05148d
commit f4a987912a
2 changed files with 39 additions and 6 deletions

View File

@ -80,10 +80,7 @@ class Frontend {
onMouseMove(e) { onMouseMove(e) {
this.popupTimerClear(); this.popupTimerClear();
if ( if (this.pendingLookup || Frontend.isMouseButton('primary', e)) {
this.pendingLookup ||
(e.buttons & 0x1) !== 0x0 // Left mouse button
) {
return; return;
} }
@ -91,7 +88,7 @@ class Frontend {
const scanningModifier = scanningOptions.modifier; const scanningModifier = scanningOptions.modifier;
if (!( if (!(
Frontend.isScanningModifierPressed(scanningModifier, e) || Frontend.isScanningModifierPressed(scanningModifier, e) ||
(scanningOptions.middleMouse && (e.buttons & 0x4) !== 0x0) // Middle mouse button (scanningOptions.middleMouse && Frontend.isMouseButton('auxiliary', e))
)) { )) {
return; return;
} }
@ -498,6 +495,23 @@ class Frontend {
default: return false; 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 = { Frontend.windowMessageHandlers = {

View File

@ -35,6 +35,7 @@ class Display {
this.persistentEventListeners = []; this.persistentEventListeners = [];
this.interactive = false; this.interactive = false;
this.eventListenersActive = false; this.eventListenersActive = false;
this.clickScanPrevent = false;
this.windowScroll = new WindowScroll(); this.windowScroll = new WindowScroll();
@ -81,6 +82,22 @@ class Display {
} }
} }
onGlossaryMousedown(e) {
if (Frontend.isMouseButton('primary', e)) {
this.clickScanPrevent = false;
}
}
onGlossaryMouseMove(e) {
this.clickScanPrevent = true;
}
onGlossaryMouseup(e) {
if (!this.clickScanPrevent && Frontend.isMouseButton('primary', e)) {
this.onTermLookup(e);
}
}
async onTermLookup(e) { async onTermLookup(e) {
try { try {
e.preventDefault(); e.preventDefault();
@ -252,7 +269,9 @@ class Display {
this.addEventListeners('.kanji-link', 'click', this.onKanjiLookup.bind(this)); this.addEventListeners('.kanji-link', 'click', this.onKanjiLookup.bind(this));
this.addEventListeners('.source-term', 'click', this.onSourceTermView.bind(this)); this.addEventListeners('.source-term', 'click', this.onSourceTermView.bind(this));
if (this.options.scanning.enablePopupSearch) { if (this.options.scanning.enablePopupSearch) {
this.addEventListeners('.glossary-item', 'click', this.onTermLookup.bind(this)); this.addEventListeners('.glossary-item', 'mouseup', this.onGlossaryMouseup.bind(this));
this.addEventListeners('.glossary-item', 'mousedown', this.onGlossaryMousedown.bind(this));
this.addEventListeners('.glossary-item', 'mousemove', this.onGlossaryMouseMove.bind(this));
} }
} else { } else {
Display.clearEventListeners(this.eventListeners); Display.clearEventListeners(this.eventListeners);