remove code duplication

This commit is contained in:
siikamiika 2019-11-03 18:03:35 +02:00
parent b0c924d4bd
commit 515345ba0a

View File

@ -34,7 +34,7 @@ class QueryParser {
} }
onMouseDown(e) { onMouseDown(e) {
if (QueryParser.isMouseButton('primary', e)) { if (Frontend.isMouseButton('primary', e)) {
this.clickScanPrevent = false; this.clickScanPrevent = false;
} }
} }
@ -43,7 +43,7 @@ class QueryParser {
if ( if (
this.search.options.scanning.clickGlossary && this.search.options.scanning.clickGlossary &&
!this.clickScanPrevent && !this.clickScanPrevent &&
QueryParser.isMouseButton('primary', e) Frontend.isMouseButton('primary', e)
) { ) {
const selectText = this.search.options.scanning.selectText; const selectText = this.search.options.scanning.selectText;
this.onTermLookup(e, {disableScroll: true, selectText}); this.onTermLookup(e, {disableScroll: true, selectText});
@ -51,18 +51,15 @@ class QueryParser {
} }
onMouseMove(e) { onMouseMove(e) {
if ( if (this.pendingLookup || Frontend.isMouseButton('primary', e)) {
this.pendingLookup ||
QueryParser.isMouseButton('primary', e)
) {
return; return;
} }
const scanningOptions = this.search.options.scanning; const scanningOptions = this.search.options.scanning;
const scanningModifier = scanningOptions.modifier; const scanningModifier = scanningOptions.modifier;
if (!( if (!(
QueryParser.isScanningModifierPressed(scanningModifier, e) || Frontend.isScanningModifierPressed(scanningModifier, e) ||
(scanningOptions.middleMouse && QueryParser.isMouseButton('auxiliary', e)) (scanningOptions.middleMouse && Frontend.isMouseButton('auxiliary', e))
)) { )) {
return; return;
} }
@ -162,31 +159,4 @@ class QueryParser {
} }
return results; return results;
} }
static isScanningModifierPressed(scanningModifier, mouseEvent) {
switch (scanningModifier) {
case 'alt': return mouseEvent.altKey;
case 'ctrl': return mouseEvent.ctrlKey;
case 'shift': return mouseEvent.shiftKey;
case 'none': return true;
default: return false;
}
}
static isMouseButton(button, mouseEvent) {
if (['mouseup', 'mousedown'].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;
}
}
} }