Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scanOnTouchTap and improve touch scanning defaults #791

Merged
merged 3 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions ext/data/schemas/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -545,6 +547,7 @@
"showAdvanced",
"searchTerms",
"searchKanji",
"scanOnTouchTap",
"scanOnTouchMove",
"scanOnTouchPress",
"scanOnTouchRelease",
Expand All @@ -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",
Expand Down
19 changes: 17 additions & 2 deletions ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ export class OptionsUtil {
this._updateVersion26,
this._updateVersion27,
this._updateVersion28,
this._updateVersion29
this._updateVersion29,
this._updateVersion30
];
/* eslint-enable @typescript-eslint/unbound-method */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
Expand Down Expand Up @@ -605,7 +606,7 @@ export class OptionsUtil {
showAdvanced: false,
searchTerms: true,
searchKanji: true,
scanOnTouchMove: true,
scanOnTouchMove: false,
scanOnPenHover: true,
scanOnPenPress: true,
scanOnPenRelease: false,
Expand Down Expand Up @@ -1217,6 +1218,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
Expand Down
1 change: 1 addition & 0 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@ export class Display extends EventDispatcher {
options: {
searchTerms: true,
searchKanji: true,
scanOnTouchTap: true,
scanOnTouchMove: false,
scanOnTouchPress: false,
scanOnTouchRelease: false,
Expand Down
13 changes: 10 additions & 3 deletions ext/js/language/text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -707,9 +710,10 @@ 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; }

void this._searchAtFromTouchEnd(x, y, inputInfo);
if (inputInfo === null || inputInfo.input === null) { return; }
if (inputInfo.input.scanOnTouchRelease || (inputInfo.input.scanOnTouchTap && this._touchTapValid)) {
void this._searchAtFromTouchEnd(x, y, inputInfo);
}
}

/**
Expand All @@ -728,6 +732,8 @@ export class TextScanner extends EventDispatcher {
* @param {TouchEvent} e
*/
_onTouchMove(e) {
this._touchTapValid = false;

if (this._primaryTouchIdentifier === null) { return; }

if (!e.cancelable) {
Expand Down Expand Up @@ -1477,6 +1483,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),
Expand Down
5 changes: 3 additions & 2 deletions ext/js/pages/settings/scan-inputs-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions ext/templates-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@

<div class="scan-input-prefix-cell scan-input-options-cell scan-input-advanced-only" data-property="touch-options"><span>Touch options:</span></div>
<div class="scan-input-content-cell scan-input-options-cell scan-input-advanced-only" data-property="touch-options">
<label class="scan-input-checkbox-item">
<label class="checkbox"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnTouchTap"><span class="checkbox-body"><span class="checkbox-fill"></span><span class="checkbox-border"></span><span class="checkbox-check"></span></span></label>
<span>Scan on touch tap</span>
</label>
<label class="scan-input-checkbox-item">
<label class="checkbox"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.scanOnTouchPress"><span class="checkbox-body"><span class="checkbox-fill"></span><span class="checkbox-border"></span><span class="checkbox-check"></span></span></label>
<span>Scan on touch press</span>
Expand Down
17 changes: 10 additions & 7 deletions test/options-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ function createProfileOptionsUpdatedTestData1() {
showAdvanced: false,
searchTerms: true,
searchKanji: true,
scanOnTouchMove: true,
scanOnTouchPress: true,
scanOnTouchTap: true,
scanOnTouchMove: false,
scanOnTouchPress: false,
scanOnTouchRelease: false,
scanOnPenMove: true,
scanOnPenHover: true,
Expand All @@ -367,8 +368,9 @@ function createProfileOptionsUpdatedTestData1() {
showAdvanced: false,
searchTerms: true,
searchKanji: true,
scanOnTouchMove: true,
scanOnTouchPress: true,
scanOnTouchTap: true,
scanOnTouchMove: false,
scanOnTouchPress: false,
scanOnTouchRelease: false,
scanOnPenMove: true,
scanOnPenHover: true,
Expand All @@ -391,8 +393,9 @@ function createProfileOptionsUpdatedTestData1() {
showAdvanced: false,
searchTerms: true,
searchKanji: true,
scanOnTouchMove: true,
scanOnTouchPress: true,
scanOnTouchTap: true,
scanOnTouchMove: false,
scanOnTouchPress: false,
scanOnTouchRelease: false,
scanOnPenMove: true,
scanOnPenHover: true,
Expand Down Expand Up @@ -599,7 +602,7 @@ function createOptionsUpdatedTestData1() {
}
],
profileCurrent: 0,
version: 29,
version: 30,
global: {
database: {
prefixWildcardsSupported: false
Expand Down
1 change: 1 addition & 0 deletions types/ext/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export type ScanningInputOptions = {
scanOnTouchMove: boolean;
scanOnTouchPress: boolean;
scanOnTouchRelease: boolean;
scanOnTouchTap: boolean;
scanOnPenMove: boolean;
scanOnPenHover: boolean;
scanOnPenReleaseHover: boolean;
Expand Down
2 changes: 2 additions & 0 deletions types/ext/text-scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type InputOptions = {
scanOnTouchMove: boolean;
scanOnTouchPress: boolean;
scanOnTouchRelease: boolean;
scanOnTouchTap: boolean;
scanOnPenMove: boolean;
scanOnPenHover: boolean;
scanOnPenReleaseHover: boolean;
Expand All @@ -84,6 +85,7 @@ export type InputConfig = {
scanOnTouchMove: boolean;
scanOnTouchPress: boolean;
scanOnTouchRelease: boolean;
scanOnTouchTap: boolean;
scanOnPenMove: boolean;
scanOnPenHover: boolean;
scanOnPenReleaseHover: boolean;
Expand Down