From de219be4303cbb1a8d40b68a4d75450dc3adf686 Mon Sep 17 00:00:00 2001 From: kuuuube Date: Wed, 10 Apr 2024 09:37:20 -0400 Subject: [PATCH 1/3] Add scanOnTouchTap --- ext/data/schemas/options-schema.json | 19 +++++++++++++------ ext/js/data/options-util.js | 16 +++++++++++++++- ext/js/display/display.js | 1 + ext/js/language/text-scanner.js | 9 +++++++-- .../pages/settings/scan-inputs-controller.js | 5 +++-- ext/templates-settings.html | 4 ++++ test/options-util.test.js | 15 +++++++++------ types/ext/settings.d.ts | 1 + types/ext/text-scanner.d.ts | 2 ++ 9 files changed, 55 insertions(+), 17 deletions(-) diff --git a/ext/data/schemas/options-schema.json b/ext/data/schemas/options-schema.json index d86eedf733..660961a811 100644 --- a/ext/data/schemas/options-schema.json +++ b/ext/data/schemas/options-schema.json @@ -463,8 +463,9 @@ "showAdvanced": false, "searchTerms": true, "searchKanji": true, - "scanOnTouchMove": true, - "scanOnTouchPress": true, + "scanOnTouchTap": true, + "scanOnTouchMove": false, + "scanOnTouchPress": false, "scanOnTouchRelease": false, "scanOnPenMove": true, "scanOnPenHover": true, @@ -487,8 +488,9 @@ "showAdvanced": false, "searchTerms": true, "searchKanji": true, - "scanOnTouchMove": true, - "scanOnTouchPress": true, + "scanOnTouchTap": true, + "scanOnTouchMove": false, + "scanOnTouchPress": false, "scanOnTouchRelease": false, "scanOnPenMove": true, "scanOnPenHover": true, @@ -545,6 +547,7 @@ "showAdvanced", "searchTerms", "searchKanji", + "scanOnTouchTap", "scanOnTouchMove", "scanOnTouchPress", "scanOnTouchRelease", @@ -569,13 +572,17 @@ "type": "boolean", "default": true }, - "scanOnTouchMove": { + "scanOnTouchTap": { "type": "boolean", "default": true }, + "scanOnTouchMove": { + "type": "boolean", + "default": false + }, "scanOnTouchPress": { "type": "boolean", - "default": true + "default": false }, "scanOnTouchRelease": { "type": "boolean", diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index af81f29ef8..cde86dd04f 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -605,7 +605,7 @@ export class OptionsUtil { showAdvanced: false, searchTerms: true, searchKanji: true, - scanOnTouchMove: true, + scanOnTouchMove: false, scanOnPenHover: true, scanOnPenPress: true, scanOnPenRelease: false, @@ -1217,6 +1217,20 @@ export class OptionsUtil { await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v29.handlebars'); } + /** + * - Added scanning.inputs[].options.scanOnTouchTap. + * - Set touch settings to be more sensible. + * @type {import('options-util').UpdateFunction} + */ + async _updateVersion30(options) { + for (const profile of options.profiles) { + for (const input of profile.options.scanning.inputs) { + input.options.scanOnTouchTap = true; + input.options.scanOnTouchPress = false; + input.options.scanOnTouchRelease = false; + } + } + } /** * @param {string} url diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 80f5e9ae80..10c1545c80 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -1844,6 +1844,7 @@ export class Display extends EventDispatcher { options: { searchTerms: true, searchKanji: true, + scanOnTouchTap: true, scanOnTouchMove: false, scanOnTouchPress: false, scanOnTouchRelease: false, diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index ad5ba12b82..4330789ec6 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -137,6 +137,8 @@ export class TextScanner extends EventDispatcher { /** @type {() => void} */ this._preventNextClickScanTimerCallback = this._onPreventNextClickScanTimeout.bind(this); + /** @type {boolean} */ + this._touchTapValid = false; /** @type {?number} */ this._primaryTouchIdentifier = null; /** @type {boolean} */ @@ -662,6 +664,7 @@ export class TextScanner extends EventDispatcher { this._preventNextContextMenu = false; this._preventNextMouseDown = false; this._preventNextClick = false; + this._touchTapValid = true; const selection = window.getSelection(); if (selection !== null && isPointInSelection(x, y, selection)) { @@ -707,8 +710,7 @@ export class TextScanner extends EventDispatcher { if (!allowSearch) { return; } const inputInfo = this._getMatchingInputGroupFromEvent('touch', 'touchEnd', e); - if (inputInfo === null || !(inputInfo.input !== null && inputInfo.input.scanOnTouchRelease)) { return; } - + if (inputInfo === null || !((inputInfo.input !== null && inputInfo.input.scanOnTouchRelease) || (inputInfo.input !== null && inputInfo.input.scanOnTouchTap && this._touchTapValid))) { return; } void this._searchAtFromTouchEnd(x, y, inputInfo); } @@ -728,6 +730,8 @@ export class TextScanner extends EventDispatcher { * @param {TouchEvent} e */ _onTouchMove(e) { + this._touchTapValid = false; + if (this._primaryTouchIdentifier === null) { return; } if (!e.cancelable) { @@ -1477,6 +1481,7 @@ export class TextScanner extends EventDispatcher { scanOnTouchMove: this._getInputBoolean(options.scanOnTouchMove), scanOnTouchPress: this._getInputBoolean(options.scanOnTouchPress), scanOnTouchRelease: this._getInputBoolean(options.scanOnTouchRelease), + scanOnTouchTap: this._getInputBoolean(options.scanOnTouchTap), scanOnPenMove: this._getInputBoolean(options.scanOnPenMove), scanOnPenHover: this._getInputBoolean(options.scanOnPenHover), scanOnPenReleaseHover: this._getInputBoolean(options.scanOnPenReleaseHover), diff --git a/ext/js/pages/settings/scan-inputs-controller.js b/ext/js/pages/settings/scan-inputs-controller.js index fcaad589e3..839a6896ed 100644 --- a/ext/js/pages/settings/scan-inputs-controller.js +++ b/ext/js/pages/settings/scan-inputs-controller.js @@ -208,8 +208,9 @@ export class ScanInputsController { showAdvanced: false, searchTerms: true, searchKanji: true, - scanOnTouchMove: true, - scanOnTouchPress: true, + scanOnTouchTap: true, + scanOnTouchMove: false, + scanOnTouchPress: false, scanOnTouchRelease: false, scanOnPenMove: true, scanOnPenHover: true, diff --git a/ext/templates-settings.html b/ext/templates-settings.html index a3a3febed5..0fb29c2235 100644 --- a/ext/templates-settings.html +++ b/ext/templates-settings.html @@ -189,6 +189,10 @@
Touch options:
+