aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-26 19:24:21 -0400
committerGitHub <noreply@github.com>2020-09-26 19:24:21 -0400
commit73dd578821d1373d4504778318e2e2f26b79a80e (patch)
tree7b96fd5bfef81de55175fc5a97ddee11cbb2ed1b /ext/mixed
parent9c7b9d666087add0f72900c045ee43ed05c5b467 (diff)
Add middle mouse prevention option (#868)
* Add preventMiddleMouse option to TextScanner * Add preventMiddleMouse options * Add options * Apply preventMiddleMouse options
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/display.js3
-rw-r--r--ext/mixed/js/text-scanner.js21
2 files changed, 19 insertions, 5 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index e5f12a1a..c7ad8894 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -251,7 +251,8 @@ class Display extends EventDispatcher {
pointerEventsEnabled: scanning.pointerEventsEnabled,
scanLength: scanning.length,
sentenceExtent: options.anki.sentenceExt,
- layoutAwareScan: scanning.layoutAwareScan
+ layoutAwareScan: scanning.layoutAwareScan,
+ preventMiddleMouse: scanning.preventMiddleMouse.onSearchQuery
}
});
}
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js
index aacc683a..b8d4faf5 100644
--- a/ext/mixed/js/text-scanner.js
+++ b/ext/mixed/js/text-scanner.js
@@ -49,6 +49,7 @@ class TextScanner extends EventDispatcher {
this._scanLength = 1;
this._sentenceExtent = 1;
this._layoutAwareScan = false;
+ this._preventMiddleMouse = false;
this._inputs = [];
this._enabled = false;
@@ -113,7 +114,7 @@ class TextScanner extends EventDispatcher {
}
}
- setOptions({inputs, deepContentScan, selectText, delay, touchInputEnabled, pointerEventsEnabled, scanLength, sentenceExtent, layoutAwareScan}) {
+ setOptions({inputs, deepContentScan, selectText, delay, touchInputEnabled, pointerEventsEnabled, scanLength, sentenceExtent, layoutAwareScan, preventMiddleMouse}) {
if (Array.isArray(inputs)) {
this._inputs = inputs.map(({
include,
@@ -151,6 +152,9 @@ class TextScanner extends EventDispatcher {
if (typeof layoutAwareScan === 'boolean') {
this._layoutAwareScan = layoutAwareScan;
}
+ if (typeof preventMiddleMouse === 'boolean') {
+ this._preventMiddleMouse = preventMiddleMouse;
+ }
}
getTextSourceContent(textSource, length, layoutAwareScan) {
@@ -282,9 +286,18 @@ class TextScanner extends EventDispatcher {
return false;
}
- if (e.button === 0) { // Primary
- this._scanTimerClear();
- this.clearSelection(false);
+ switch (e.button) {
+ case 0: // Primary
+ this._scanTimerClear();
+ this.clearSelection(false);
+ break;
+ case 1: // Middle
+ if (this._preventMiddleMouse) {
+ e.preventDefault();
+ e.stopPropagation();
+ return false;
+ }
+ break;
}
}