aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/text-scanner.js
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/js/text-scanner.js
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/js/text-scanner.js')
-rw-r--r--ext/mixed/js/text-scanner.js21
1 files changed, 17 insertions, 4 deletions
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;
}
}