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
This commit is contained in:
toasted-nutbread 2020-09-27 11:46:37 -04:00 committed by GitHub
parent 73dd578821
commit cdd649ea3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 14 deletions

View File

@ -352,11 +352,13 @@
}, },
"options": { "options": {
"showAdvanced": false, "showAdvanced": false,
"scanOnTouchMove": true,
"scanOnPenHover": true, "scanOnPenHover": true,
"scanOnPenPress": true, "scanOnPenPress": true,
"scanOnPenRelease": false, "scanOnPenRelease": false,
"searchTerms": true, "searchTerms": true,
"searchKanji": true "searchKanji": true,
"preventTouchScrolling": false
} }
}, },
{ {
@ -369,11 +371,13 @@
}, },
"options": { "options": {
"showAdvanced": false, "showAdvanced": false,
"scanOnTouchMove": true,
"scanOnPenHover": true, "scanOnPenHover": true,
"scanOnPenPress": true, "scanOnPenPress": true,
"scanOnPenRelease": false, "scanOnPenRelease": false,
"searchTerms": true, "searchTerms": true,
"searchKanji": true "searchKanji": true,
"preventTouchScrolling": true
} }
} }
], ],
@ -419,17 +423,23 @@
"type": "object", "type": "object",
"required": [ "required": [
"showAdvanced", "showAdvanced",
"scanOnTouchMove",
"scanOnPenHover", "scanOnPenHover",
"scanOnPenPress", "scanOnPenPress",
"scanOnPenRelease", "scanOnPenRelease",
"searchTerms", "searchTerms",
"searchKanji" "searchKanji",
"preventTouchScrolling"
], ],
"properties": { "properties": {
"showAdvanced": { "showAdvanced": {
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"scanOnTouchMove": {
"type": "boolean",
"default": true
},
"scanOnPenHover": { "scanOnPenHover": {
"type": "boolean", "type": "boolean",
"default": true "default": true
@ -449,6 +459,10 @@
"searchKanji": { "searchKanji": {
"type": "boolean", "type": "boolean",
"default": true "default": true
},
"preventTouchScrolling": {
"type": "boolean",
"default": true
} }
} }
} }

View File

@ -522,11 +522,13 @@ class OptionsUtil {
} }
const createInputDefaultOptions = () => ({ const createInputDefaultOptions = () => ({
showAdvanced: false, showAdvanced: false,
scanOnTouchMove: true,
scanOnPenHover: true, scanOnPenHover: true,
scanOnPenPress: true, scanOnPenPress: true,
scanOnPenRelease: false, scanOnPenRelease: false,
searchTerms: true, searchTerms: true,
searchKanji: true searchKanji: true,
preventTouchScrolling: true
}); });
for (const {options: profileOptions} of options.profiles) { for (const {options: profileOptions} of options.profiles) {
profileOptions.general.usePopupWindow = false; profileOptions.general.usePopupWindow = false;

View File

@ -99,11 +99,13 @@ class ScanInputsController {
types: {mouse: true, touch: false, pen: false}, types: {mouse: true, touch: false, pen: false},
options: { options: {
showAdvanced: false, showAdvanced: false,
scanOnTouchMove: true,
scanOnPenHover: true, scanOnPenHover: true,
scanOnPenPress: true, scanOnPenPress: true,
scanOnPenRelease: false, scanOnPenRelease: false,
searchTerms: true, searchTerms: true,
searchKanji: true searchKanji: true,
preventTouchScrolling: true
} }
}] }]
}]); }]);

View File

@ -484,9 +484,11 @@
<div class="scan-input-type-list-container form-control"><div> <div class="scan-input-type-list-container form-control"><div>
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.searchTerms"><span>Search for terms</span></label></div> <div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.searchTerms"><span>Search for terms</span></label></div>
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.searchKanji"><span>Search for kanji</span></label></div> <div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.searchKanji"><span>Search for kanji</span></label></div>
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnTouchMove"><span>Scan on touch move</span></label></div>
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenHover"><span>Scan on pen hover</span></label></div> <div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenHover"><span>Scan on pen hover</span></label></div>
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenPress"><span>Scan on pen press</span></label></div> <div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenPress"><span>Scan on pen press</span></label></div>
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenRelease"><span>Scan on pen release</span></label></div> <div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnPenRelease"><span>Scan on pen release</span></label></div>
<div><label class="scan-input-toggle"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.preventTouchScrolling"><span>Prevent touch/pen scrolling</span></label></div>
</div></div> </div></div>
</div></div> </div></div>
</div> </div>

View File

@ -120,12 +120,12 @@ class TextScanner extends EventDispatcher {
include, include,
exclude, exclude,
types, types,
options: {scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji} options: {scanOnTouchMove, scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji, preventTouchScrolling}
}) => ({ }) => ({
include: this._getInputArray(include), include: this._getInputArray(include),
exclude: this._getInputArray(exclude), exclude: this._getInputArray(exclude),
types: this._getInputTypeSet(types), types: this._getInputTypeSet(types),
options: {scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji} options: {scanOnTouchMove, scanOnPenHover, scanOnPenPress, scanOnPenRelease, searchTerms, searchKanji, preventTouchScrolling}
})); }));
} }
if (typeof deepContentScan === 'boolean') { if (typeof deepContentScan === 'boolean') {
@ -392,7 +392,9 @@ class TextScanner extends EventDispatcher {
const inputInfo = this._getMatchingInputGroupFromEvent(e, type); const inputInfo = this._getMatchingInputGroupFromEvent(e, type);
if (inputInfo === null) { return; } if (inputInfo === null) { return; }
if (inputInfo.input.options.scanOnTouchMove) {
this._searchAt(primaryTouch.clientX, primaryTouch.clientY, type, 'touchMove', inputInfo); this._searchAt(primaryTouch.clientX, primaryTouch.clientY, type, 'touchMove', inputInfo);
}
e.preventDefault(); // Disable scroll e.preventDefault(); // Disable scroll
} }
@ -497,7 +499,7 @@ class TextScanner extends EventDispatcher {
} }
const inputInfo = this._getMatchingInputGroupFromEvent(e, 'touch'); 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); this._searchAt(e.clientX, e.clientY, 'touch', 'touchMove', inputInfo);
} }
@ -748,6 +750,7 @@ class TextScanner extends EventDispatcher {
if (inputInfo === null) { return; } if (inputInfo === null) { return; }
const textSourceCurrentPrevious = this._textSourceCurrent !== null ? this._textSourceCurrent.clone() : null; const textSourceCurrentPrevious = this._textSourceCurrent !== null ? this._textSourceCurrent.clone() : null;
const preventScroll = inputInfo.input.options.preventTouchScrolling;
await this._searchAt(x, y, type, cause, inputInfo); await this._searchAt(x, y, type, cause, inputInfo);
@ -755,7 +758,7 @@ class TextScanner extends EventDispatcher {
this._textSourceCurrent !== null && this._textSourceCurrent !== null &&
!this._textSourceCurrent.equals(textSourceCurrentPrevious) !this._textSourceCurrent.equals(textSourceCurrentPrevious)
) { ) {
this._preventScroll = true; this._preventScroll = preventScroll;
this._preventNextContextMenu = true; this._preventNextContextMenu = true;
this._preventNextMouseDown = true; this._preventNextMouseDown = true;
} }
@ -776,13 +779,15 @@ class TextScanner extends EventDispatcher {
return; return;
} }
const preventScroll = inputInfo.input.options.preventTouchScrolling;
await this._searchAt(x, y, type, cause, inputInfo); await this._searchAt(x, y, type, cause, inputInfo);
if ( if (
prevent && prevent &&
this._textSourceCurrent !== null this._textSourceCurrent !== null
) { ) {
this._preventScroll = true; this._preventScroll = preventScroll;
this._preventNextContextMenu = true; this._preventNextContextMenu = true;
this._preventNextMouseDown = true; this._preventNextMouseDown = true;
this._preventNextClick = true; this._preventNextClick = true;

View File

@ -333,11 +333,13 @@ function createProfileOptionsUpdatedTestData1() {
}, },
options: { options: {
showAdvanced: false, showAdvanced: false,
scanOnTouchMove: true,
scanOnPenHover: true, scanOnPenHover: true,
scanOnPenPress: true, scanOnPenPress: true,
scanOnPenRelease: false, scanOnPenRelease: false,
searchTerms: true, searchTerms: true,
searchKanji: true searchKanji: true,
preventTouchScrolling: true
} }
}, },
{ {
@ -350,11 +352,13 @@ function createProfileOptionsUpdatedTestData1() {
}, },
options: { options: {
showAdvanced: false, showAdvanced: false,
scanOnTouchMove: true,
scanOnPenHover: true, scanOnPenHover: true,
scanOnPenPress: true, scanOnPenPress: true,
scanOnPenRelease: false, scanOnPenRelease: false,
searchTerms: true, searchTerms: true,
searchKanji: true searchKanji: true,
preventTouchScrolling: true
} }
}, },
{ {
@ -367,11 +371,13 @@ function createProfileOptionsUpdatedTestData1() {
}, },
options: { options: {
showAdvanced: false, showAdvanced: false,
scanOnTouchMove: true,
scanOnPenHover: true, scanOnPenHover: true,
scanOnPenPress: true, scanOnPenPress: true,
scanOnPenRelease: false, scanOnPenRelease: false,
searchTerms: true, searchTerms: true,
searchKanji: true searchKanji: true,
preventTouchScrolling: true
} }
} }
] ]