Create functions for the cases of isMouseButton
jshint was showing a warning that there was no break statement after the first case, which there doesn't need to be. The most straightforward way to fix this without using the unclear // jshint ignore:line is to just have two functions. This change also updates invocations of isMouseButton to use the exact case function, as this will remove the need to check the case of mosueEvent.type. This was done because onMouseMove is invoked at a high frequency.
This commit is contained in:
parent
dad685dba4
commit
d9b4404075
@ -80,7 +80,7 @@ class Frontend {
|
|||||||
onMouseMove(e) {
|
onMouseMove(e) {
|
||||||
this.popupTimerClear();
|
this.popupTimerClear();
|
||||||
|
|
||||||
if (this.pendingLookup || Frontend.isMouseButton('primary', e)) {
|
if (this.pendingLookup || Frontend.isMouseButtonDown('primary', e)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,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 && Frontend.isMouseButton('auxiliary', e))
|
(scanningOptions.middleMouse && Frontend.isMouseButtonDown('auxiliary', e))
|
||||||
)) {
|
)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -504,18 +504,30 @@ class Frontend {
|
|||||||
switch (mouseEvent.type) {
|
switch (mouseEvent.type) {
|
||||||
case 'mouseup':
|
case 'mouseup':
|
||||||
case 'mousedown':
|
case 'mousedown':
|
||||||
case 'click': switch (button) {
|
case 'click':
|
||||||
case 'primary': return mouseEvent.button === 0;
|
return Frontend.isMouseButtonPressed(button, mouseEvent);
|
||||||
case 'secondary': return mouseEvent.button === 2;
|
default:
|
||||||
case 'auxiliary': return mouseEvent.button === 1;
|
return Frontend.isMouseButtonDown(button, mouseEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static isMouseButtonPressed(button, mouseEvent) {
|
||||||
|
const mouseEventButton = mouseEvent.button;
|
||||||
|
switch (button) {
|
||||||
|
case 'primary': return mouseEventButton === 0;
|
||||||
|
case 'secondary': return mouseEventButton === 2;
|
||||||
|
case 'auxiliary': return mouseEventButton === 1;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
default: 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static isMouseButtonDown(button, mouseEvent) {
|
||||||
|
const mouseEventButtons = mouseEvent.buttons;
|
||||||
|
switch (button) {
|
||||||
|
case 'primary': return (mouseEventButtons & 0x1) !== 0x0;
|
||||||
|
case 'secondary': return (mouseEventButtons & 0x2) !== 0x0;
|
||||||
|
case 'auxiliary': return (mouseEventButtons & 0x4) !== 0x0;
|
||||||
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ class Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onGlossaryMouseDown(e) {
|
onGlossaryMouseDown(e) {
|
||||||
if (Frontend.isMouseButton('primary', e)) {
|
if (Frontend.isMouseButtonPressed('primary', e)) {
|
||||||
this.clickScanPrevent = false;
|
this.clickScanPrevent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ class Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onGlossaryMouseUp(e) {
|
onGlossaryMouseUp(e) {
|
||||||
if (!this.clickScanPrevent && Frontend.isMouseButton('primary', e)) {
|
if (!this.clickScanPrevent && Frontend.isMouseButtonPressed('primary', e)) {
|
||||||
this.onTermLookup(e);
|
this.onTermLookup(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user