click & text selection improvements on search page
This commit is contained in:
parent
c78ca36f3d
commit
bc66f254ea
@ -21,25 +21,39 @@ class QueryParser {
|
|||||||
constructor(search) {
|
constructor(search) {
|
||||||
this.search = search;
|
this.search = search;
|
||||||
this.pendingLookup = false;
|
this.pendingLookup = false;
|
||||||
|
this.clickScanPrevent = false;
|
||||||
|
|
||||||
this.queryParser = document.querySelector('#query-parser');
|
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) {
|
onError(error) {
|
||||||
logError(error, false);
|
logError(error, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
onClick(e) {
|
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;
|
const selectText = this.search.options.scanning.selectText;
|
||||||
this.onTermLookup(e, {disableScroll: true, selectText});
|
this.onTermLookup(e, {disableScroll: true, selectText});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMouseMove(e) {
|
onMouseMove(e) {
|
||||||
if (
|
if (
|
||||||
this.pendingLookup ||
|
this.pendingLookup ||
|
||||||
(e.buttons & 0x1) !== 0x0 // Left mouse button
|
QueryParser.isMouseButton('primary', e)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -48,7 +62,7 @@ class QueryParser {
|
|||||||
const scanningModifier = scanningOptions.modifier;
|
const scanningModifier = scanningOptions.modifier;
|
||||||
if (!(
|
if (!(
|
||||||
QueryParser.isScanningModifierPressed(scanningModifier, e) ||
|
QueryParser.isScanningModifierPressed(scanningModifier, e) ||
|
||||||
(scanningOptions.middleMouse && (e.buttons & 0x4) !== 0x0) // Middle mouse button
|
(scanningOptions.middleMouse && QueryParser.isMouseButton('auxiliary', e))
|
||||||
)) {
|
)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -57,6 +71,12 @@ class QueryParser {
|
|||||||
this.onTermLookup(e, {disableScroll: true, disableHistory: true, selectText});
|
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) {
|
onTermLookup(e, params) {
|
||||||
this.pendingLookup = true;
|
this.pendingLookup = true;
|
||||||
(async () => {
|
(async () => {
|
||||||
@ -124,8 +144,7 @@ class QueryParser {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
element.addEventListener('mouseleave', (e) => {
|
element.addEventListener('mouseleave', (e) => {
|
||||||
clearTimeout(e.target.dataset.timer);
|
this.onMouseLeave(e);
|
||||||
delete e.target.dataset.timer;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,4 +172,21 @@ class QueryParser {
|
|||||||
default: return false;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user