Add middle mouse prevention option (#868)
* Add preventMiddleMouse option to TextScanner * Add preventMiddleMouse options * Add options * Apply preventMiddleMouse options
This commit is contained in:
parent
9c7b9d6660
commit
73dd578821
@ -320,6 +320,7 @@
|
||||
"type": "object",
|
||||
"required": [
|
||||
"inputs",
|
||||
"preventMiddleMouse",
|
||||
"touchInputEnabled",
|
||||
"pointerEventsEnabled",
|
||||
"selectText",
|
||||
@ -454,6 +455,33 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"preventMiddleMouse": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"onWebPages",
|
||||
"onPopupPages",
|
||||
"onSearchPages",
|
||||
"onSearchQuery"
|
||||
],
|
||||
"properties": {
|
||||
"onWebPages": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"onPopupPages": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"onSearchPages": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"onSearchQuery": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"touchInputEnabled": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
|
@ -507,6 +507,7 @@ class OptionsUtil {
|
||||
// Added hideDelay.
|
||||
// Added inputs to profileOptions.scanning.
|
||||
// Added pointerEventsEnabled to profileOptions.scanning.
|
||||
// Added preventMiddleMouse to profileOptions.scanning.
|
||||
for (const {conditionGroups} of options.profiles) {
|
||||
for (const {conditions} of conditionGroups) {
|
||||
for (const condition of conditions) {
|
||||
@ -531,6 +532,12 @@ class OptionsUtil {
|
||||
profileOptions.general.usePopupWindow = false;
|
||||
profileOptions.scanning.hideDelay = 0;
|
||||
profileOptions.scanning.pointerEventsEnabled = false;
|
||||
profileOptions.scanning.preventMiddleMouse = {
|
||||
onWebPages: false,
|
||||
onPopupPages: false,
|
||||
onSearchPages: false,
|
||||
onSearchQuery: false
|
||||
};
|
||||
|
||||
const {modifier, middleMouse} = profileOptions.scanning;
|
||||
delete profileOptions.scanning.modifier;
|
||||
|
@ -414,6 +414,16 @@
|
||||
<label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.deepDomScan"> Deep content scan</label>
|
||||
</div>
|
||||
|
||||
<div class="checkbox options-advanced">
|
||||
<strong>Prevent middle mouse button actions on:</strong>
|
||||
<div style="margin-left: 1em;">
|
||||
<label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.preventMiddleMouse.onWebPages"> Webpages</label><br>
|
||||
<label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.preventMiddleMouse.onPopupPages"> Popups</label><br>
|
||||
<label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.preventMiddleMouse.onSearchPages"> Search page</label><br>
|
||||
<label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.preventMiddleMouse.onSearchQuery"> Search query</label><br>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group options-advanced">
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
|
@ -320,6 +320,7 @@ class Frontend {
|
||||
|
||||
await this._updatePopup();
|
||||
|
||||
const preventMiddleMouse = this._getPreventMiddleMouseValueForPageType(scanningOptions.preventMiddleMouse);
|
||||
this._textScanner.setOptions({
|
||||
inputs: scanningOptions.inputs,
|
||||
deepContentScan: scanningOptions.deepDomScan,
|
||||
@ -329,7 +330,8 @@ class Frontend {
|
||||
pointerEventsEnabled: scanningOptions.pointerEventsEnabled,
|
||||
scanLength: scanningOptions.length,
|
||||
sentenceExtent: options.anki.sentenceExt,
|
||||
layoutAwareScan: scanningOptions.layoutAwareScan
|
||||
layoutAwareScan: scanningOptions.layoutAwareScan,
|
||||
preventMiddleMouse
|
||||
});
|
||||
this._updateTextScannerEnabled();
|
||||
|
||||
@ -616,4 +618,13 @@ class Frontend {
|
||||
await this._updatePendingOptions();
|
||||
return await this.getOptionsContext();
|
||||
}
|
||||
|
||||
_getPreventMiddleMouseValueForPageType(preventMiddleMouseOptions) {
|
||||
switch (this._pageType) {
|
||||
case 'web': return preventMiddleMouseOptions.onWebPages;
|
||||
case 'popup': return preventMiddleMouseOptions.onPopupPages;
|
||||
case 'search': return preventMiddleMouseOptions.onSearchPages;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,6 +316,12 @@ function createProfileOptionsUpdatedTestData1() {
|
||||
layoutAwareScan: false,
|
||||
hideDelay: 0,
|
||||
pointerEventsEnabled: false,
|
||||
preventMiddleMouse: {
|
||||
onWebPages: false,
|
||||
onPopupPages: false,
|
||||
onSearchPages: false,
|
||||
onSearchQuery: false
|
||||
},
|
||||
inputs: [
|
||||
{
|
||||
include: 'shift',
|
||||
|
Loading…
Reference in New Issue
Block a user