aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/display.js28
-rw-r--r--ext/mixed/js/text-scanner.js45
2 files changed, 56 insertions, 17 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 418707ca..927c2c2c 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -218,11 +218,29 @@ class Display extends EventDispatcher {
}
async updateOptions() {
- this._options = await api.optionsGet(this.getOptionsContext());
- this._updateDocumentOptions(this._options);
- this._updateTheme(this._options.general.popupTheme);
- this.setCustomCss(this._options.general.customPopupCss);
- this._queryParser.setOptions(this._options);
+ const options = await api.optionsGet(this.getOptionsContext());
+ const scanning = options.scanning;
+ this._options = options;
+
+ this._updateDocumentOptions(options);
+ this._updateTheme(options.general.popupTheme);
+ this.setCustomCss(options.general.customPopupCss);
+
+ this._queryParser.setOptions({
+ selectedParser: options.parsing.selectedParser,
+ scanLength: scanning.length,
+ sentenceExtent: options.anki.sentenceExt,
+ layoutAwareScan: scanning.layoutAwareScan,
+ termSpacing: options.parsing.termSpacing,
+ scanning: {
+ deepContentScan: scanning.deepDomScan,
+ selectText: scanning.selectText,
+ modifier: scanning.modifier,
+ useMiddleMouse: scanning.middleMouse,
+ delay: scanning.delay,
+ touchInputEnabled: scanning.touchInputEnabled
+ }
+ });
}
addMultipleEventListeners(selector, type, listener, options) {
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js
index 7c705fc8..61e9256d 100644
--- a/ext/mixed/js/text-scanner.js
+++ b/ext/mixed/js/text-scanner.js
@@ -36,7 +36,13 @@ class TextScanner extends EventDispatcher {
this._textSourceCurrent = null;
this._textSourceCurrentSelected = false;
this._pendingLookup = false;
- this._options = null;
+
+ this._deepContentScan = false;
+ this._selectText = false;
+ this._modifier = 'none';
+ this._useMiddleMouse = false;
+ this._delay = 0;
+ this._touchInputEnabled = false;
this._enabled = false;
this._eventListeners = new EventListenerCollection();
@@ -85,8 +91,25 @@ class TextScanner extends EventDispatcher {
}
}
- setOptions(options) {
- this._options = options;
+ setOptions({deepContentScan, selectText, modifier, useMiddleMouse, delay, touchInputEnabled}) {
+ if (typeof deepContentScan === 'boolean') {
+ this._deepContentScan = deepContentScan;
+ }
+ if (typeof selectText === 'boolean') {
+ this._selectText = selectText;
+ }
+ if (typeof modifier === 'string') {
+ this._modifier = modifier;
+ }
+ if (typeof useMiddleMouse === 'boolean') {
+ this._useMiddleMouse = useMiddleMouse;
+ }
+ if (typeof delay === 'number') {
+ this._delay = delay;
+ }
+ if (typeof touchInputEnabled === 'boolean') {
+ this._touchInputEnabled = false;
+ }
}
async searchAt(x, y, cause) {
@@ -101,7 +124,7 @@ class TextScanner extends EventDispatcher {
return;
}
- const textSource = docRangeFromPoint(x, y, this._options.scanning.deepDomScan);
+ const textSource = docRangeFromPoint(x, y, this._deepContentScan);
try {
if (this._textSourceCurrent !== null && this._textSourceCurrent.equals(textSource)) {
return;
@@ -162,7 +185,7 @@ class TextScanner extends EventDispatcher {
setCurrentTextSource(textSource) {
this._textSourceCurrent = textSource;
- if (this._options.scanning.selectText) {
+ if (this._selectText) {
this._textSourceCurrent.select();
this._textSourceCurrentSelected = true;
} else {
@@ -188,17 +211,15 @@ class TextScanner extends EventDispatcher {
const modifiers = DOM.getActiveModifiers(e);
this.trigger('activeModifiersChanged', {modifiers});
- const scanningOptions = this._options.scanning;
- const scanningModifier = scanningOptions.modifier;
if (!(
- this._isScanningModifierPressed(scanningModifier, e) ||
- (scanningOptions.middleMouse && DOM.isMouseButtonDown(e, 'auxiliary'))
+ this._isScanningModifierPressed(this._modifier, e) ||
+ (this._useMiddleMouse && DOM.isMouseButtonDown(e, 'auxiliary'))
)) {
return;
}
const search = async () => {
- if (scanningModifier === 'none') {
+ if (this._modifier === 'none') {
if (!await this._scanTimerWait()) {
// Aborted
return;
@@ -325,7 +346,7 @@ class TextScanner extends EventDispatcher {
}
async _scanTimerWait() {
- const delay = this._options.scanning.delay;
+ const delay = this._delay;
const promise = promiseTimeout(delay, true);
this._scanTimerPromise = promise;
try {
@@ -346,7 +367,7 @@ class TextScanner extends EventDispatcher {
_hookEvents() {
const eventListenerInfos = this._getMouseEventListeners();
- if (this._options.scanning.touchInputEnabled) {
+ if (this._touchInputEnabled) {
eventListenerInfos.push(...this._getTouchEventListeners());
}