From cdd649ea3d3c933b571db1b00bc40162b4da8c01 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 27 Sep 2020 11:46:37 -0400 Subject: Add scan on touch move and prevent touch scroll options (#871) * Add scanOnTouchMove/preventTouchScrolling scanning input options * Add settings controls * Support scanOnTouchMove in TextScanner * Support preventTouchScrolling in TextScanner --- ext/bg/data/options-schema.json | 20 +++++++++++++++++--- ext/bg/js/options.js | 4 +++- ext/bg/js/settings/scan-inputs-controller.js | 4 +++- ext/bg/settings.html | 2 ++ ext/mixed/js/text-scanner.js | 17 +++++++++++------ test/test-options-util.js | 12 +++++++++--- 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json index 80f8d782..0b0a9259 100644 --- a/ext/bg/data/options-schema.json +++ b/ext/bg/data/options-schema.json @@ -352,11 +352,13 @@ }, "options": { "showAdvanced": false, + "scanOnTouchMove": true, "scanOnPenHover": true, "scanOnPenPress": true, "scanOnPenRelease": false, "searchTerms": true, - "searchKanji": true + "searchKanji": true, + "preventTouchScrolling": false } }, { @@ -369,11 +371,13 @@ }, "options": { "showAdvanced": false, + "scanOnTouchMove": true, "scanOnPenHover": true, "scanOnPenPress": true, "scanOnPenRelease": false, "searchTerms": true, - "searchKanji": true + "searchKanji": true, + "preventTouchScrolling": true } } ], @@ -419,17 +423,23 @@ "type": "object", "required": [ "showAdvanced", + "scanOnTouchMove", "scanOnPenHover", "scanOnPenPress", "scanOnPenRelease", "searchTerms", - "searchKanji" + "searchKanji", + "preventTouchScrolling" ], "properties": { "showAdvanced": { "type": "boolean", "default": false }, + "scanOnTouchMove": { + "type": "boolean", + "default": true + }, "scanOnPenHover": { "type": "boolean", "default": true @@ -449,6 +459,10 @@ "searchKanji": { "type": "boolean", "default": true + }, + "preventTouchScrolling": { + "type": "boolean", + "default": true } } } diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index cf24645a..f83dad6d 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -522,11 +522,13 @@ class OptionsUtil { } const createInputDefaultOptions = () => ({ showAdvanced: false, + scanOnTouchMove: true, scanOnPenHover: true, scanOnPenPress: true, scanOnPenRelease: false, searchTerms: true, - searchKanji: true + searchKanji: true, + preventTouchScrolling: true }); for (const {options: profileOptions} of options.profiles) { profileOptions.general.usePopupWindow = false; diff --git a/ext/bg/js/settings/scan-inputs-controller.js b/ext/bg/js/settings/scan-inputs-controller.js index b6498d7c..0606d142 100644 --- a/ext/bg/js/settings/scan-inputs-controller.js +++ b/ext/bg/js/settings/scan-inputs-controller.js @@ -99,11 +99,13 @@ class ScanInputsController { types: {mouse: true, touch: false, pen: false}, options: { showAdvanced: false, + scanOnTouchMove: true, scanOnPenHover: true, scanOnPenPress: true, scanOnPenRelease: false, searchTerms: true, - searchKanji: true + searchKanji: true, + preventTouchScrolling: true } }] }]); diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 8dea0245..86535af4 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -484,9 +484,11 @@
+
+
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js index b8d4faf5..fe20cb1c 100644 --- a/ext/mixed/js/text-scanner.js +++ b/ext/mixed/js/text-scanner.js @@ -120,12 +120,12 @@ class TextScanner extends EventDispatcher { include, exclude, types, - options: {scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji} + options: {scanOnTouchMove, scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji, preventTouchScrolling} }) => ({ include: this._getInputArray(include), exclude: this._getInputArray(exclude), types: this._getInputTypeSet(types), - options: {scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji} + options: {scanOnTouchMove, scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji, preventTouchScrolling} })); } if (typeof deepContentScan === 'boolean') { @@ -392,7 +392,9 @@ class TextScanner extends EventDispatcher { const inputInfo = this._getMatchingInputGroupFromEvent(e, type); if (inputInfo === null) { return; } - this._searchAt(primaryTouch.clientX, primaryTouch.clientY, type, 'touchMove', inputInfo); + if (inputInfo.input.options.scanOnTouchMove) { + this._searchAt(primaryTouch.clientX, primaryTouch.clientY, type, 'touchMove', inputInfo); + } e.preventDefault(); // Disable scroll } @@ -497,7 +499,7 @@ class TextScanner extends EventDispatcher { } const inputInfo = this._getMatchingInputGroupFromEvent(e, 'touch'); - if (inputInfo === null) { return; } + if (inputInfo === null || !inputInfo.input.options.scanOnTouchMove) { return; } this._searchAt(e.clientX, e.clientY, 'touch', 'touchMove', inputInfo); } @@ -748,6 +750,7 @@ class TextScanner extends EventDispatcher { if (inputInfo === null) { return; } const textSourceCurrentPrevious = this._textSourceCurrent !== null ? this._textSourceCurrent.clone() : null; + const preventScroll = inputInfo.input.options.preventTouchScrolling; await this._searchAt(x, y, type, cause, inputInfo); @@ -755,7 +758,7 @@ class TextScanner extends EventDispatcher { this._textSourceCurrent !== null && !this._textSourceCurrent.equals(textSourceCurrentPrevious) ) { - this._preventScroll = true; + this._preventScroll = preventScroll; this._preventNextContextMenu = true; this._preventNextMouseDown = true; } @@ -776,13 +779,15 @@ class TextScanner extends EventDispatcher { return; } + const preventScroll = inputInfo.input.options.preventTouchScrolling; + await this._searchAt(x, y, type, cause, inputInfo); if ( prevent && this._textSourceCurrent !== null ) { - this._preventScroll = true; + this._preventScroll = preventScroll; this._preventNextContextMenu = true; this._preventNextMouseDown = true; this._preventNextClick = true; diff --git a/test/test-options-util.js b/test/test-options-util.js index b1b6dab7..c8eb3b16 100644 --- a/test/test-options-util.js +++ b/test/test-options-util.js @@ -333,11 +333,13 @@ function createProfileOptionsUpdatedTestData1() { }, options: { showAdvanced: false, + scanOnTouchMove: true, scanOnPenHover: true, scanOnPenPress: true, scanOnPenRelease: false, searchTerms: true, - searchKanji: true + searchKanji: true, + preventTouchScrolling: true } }, { @@ -350,11 +352,13 @@ function createProfileOptionsUpdatedTestData1() { }, options: { showAdvanced: false, + scanOnTouchMove: true, scanOnPenHover: true, scanOnPenPress: true, scanOnPenRelease: false, searchTerms: true, - searchKanji: true + searchKanji: true, + preventTouchScrolling: true } }, { @@ -367,11 +371,13 @@ function createProfileOptionsUpdatedTestData1() { }, options: { showAdvanced: false, + scanOnTouchMove: true, scanOnPenHover: true, scanOnPenPress: true, scanOnPenRelease: false, searchTerms: true, - searchKanji: true + searchKanji: true, + preventTouchScrolling: true } } ] -- cgit v1.2.3