aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-11-03 17:04:32 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2019-11-23 17:45:44 +0200
commitbc66f254ea719bb254cafabe5eb127ec7c340b1e (patch)
tree37de2da1091ecf788ebedd84b88458778c69024d /ext
parentc78ca36f3dca8a3ca32923bd65e84a59d0f51613 (diff)
click & text selection improvements on search page
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/search-query-parser.js52
1 files changed, 44 insertions, 8 deletions
diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js
index cff48c46..60b94ca8 100644
--- a/ext/bg/js/search-query-parser.js
+++ b/ext/bg/js/search-query-parser.js
@@ -21,25 +21,39 @@ class QueryParser {
constructor(search) {
this.search = search;
this.pendingLookup = false;
+ this.clickScanPrevent = false;
this.queryParser = document.querySelector('#query-parser');
- this.queryParser.addEventListener('click', (e) => this.onClick(e));
+ this.queryParser.addEventListener('mousedown', (e) => this.onMouseDown(e));
+ this.queryParser.addEventListener('mouseup', (e) => this.onMouseUp(e));
}
onError(error) {
logError(error, false);
}
- onClick(e) {
- const selectText = this.search.options.scanning.selectText;
- this.onTermLookup(e, {disableScroll: true, selectText});
+ onMouseDown(e) {
+ if (QueryParser.isMouseButton('primary', e)) {
+ this.clickScanPrevent = false;
+ }
+ }
+
+ onMouseUp(e) {
+ if (
+ this.search.options.scanning.clickGlossary &&
+ !this.clickScanPrevent &&
+ QueryParser.isMouseButton('primary', e)
+ ) {
+ const selectText = this.search.options.scanning.selectText;
+ this.onTermLookup(e, {disableScroll: true, selectText});
+ }
}
onMouseMove(e) {
if (
this.pendingLookup ||
- (e.buttons & 0x1) !== 0x0 // Left mouse button
+ QueryParser.isMouseButton('primary', e)
) {
return;
}
@@ -48,7 +62,7 @@ class QueryParser {
const scanningModifier = scanningOptions.modifier;
if (!(
QueryParser.isScanningModifierPressed(scanningModifier, e) ||
- (scanningOptions.middleMouse && (e.buttons & 0x4) !== 0x0) // Middle mouse button
+ (scanningOptions.middleMouse && QueryParser.isMouseButton('auxiliary', e))
)) {
return;
}
@@ -57,6 +71,12 @@ class QueryParser {
this.onTermLookup(e, {disableScroll: true, disableHistory: true, selectText});
}
+ onMouseLeave(e) {
+ this.clickScanPrevent = true;
+ clearTimeout(e.target.dataset.timer);
+ delete e.target.dataset.timer;
+ }
+
onTermLookup(e, params) {
this.pendingLookup = true;
(async () => {
@@ -124,8 +144,7 @@ class QueryParser {
}
});
element.addEventListener('mouseleave', (e) => {
- clearTimeout(e.target.dataset.timer);
- delete e.target.dataset.timer;
+ this.onMouseLeave(e);
});
}
@@ -153,4 +172,21 @@ class QueryParser {
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;
+ }
+ }
}