Skip to content

Commit

Permalink
Add minimumTouchTime setting to scanning inputs settings (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube authored Jan 21, 2025
1 parent bc62b8b commit 4197228
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 4 deletions.
13 changes: 10 additions & 3 deletions ext/data/schemas/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@
"scanOnPenPress": true,
"scanOnPenRelease": false,
"preventTouchScrolling": false,
"preventPenScrolling": false
"preventPenScrolling": false,
"minimumTouchTime": 0
}
},
{
Expand All @@ -524,7 +525,8 @@
"scanOnPenPress": true,
"scanOnPenRelease": false,
"preventTouchScrolling": true,
"preventPenScrolling": true
"preventPenScrolling": true,
"minimumTouchTime": 0
}
}
],
Expand Down Expand Up @@ -583,7 +585,8 @@
"scanOnPenPress",
"scanOnPenRelease",
"preventTouchScrolling",
"preventPenScrolling"
"preventPenScrolling",
"minimumTouchTime"
],
"properties": {
"showAdvanced": {
Expand Down Expand Up @@ -641,6 +644,10 @@
"preventPenScrolling": {
"type": "boolean",
"default": true
},
"minimumTouchTime": {
"type": "number",
"default": 0
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ export class OptionsUtil {
this._updateVersion54,
this._updateVersion55,
this._updateVersion56,
this._updateVersion57,
];
/* eslint-enable @typescript-eslint/unbound-method */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
Expand Down Expand Up @@ -642,6 +643,7 @@ export class OptionsUtil {
scanOnPenPress: true,
scanOnPenRelease: false,
preventTouchScrolling: true,
minimumTouchTime: 0,
});
for (const {options: profileOptions} of options.profiles) {
profileOptions.general.usePopupWindow = false;
Expand Down Expand Up @@ -1553,6 +1555,18 @@ export class OptionsUtil {
}
}

/**
* - Added scanning.inputs[].options.minimumTouchTime.
* @type {import('options-util').UpdateFunction}
*/
async _updateVersion57(options) {
for (const profile of options.profiles) {
for (const input of profile.options.scanning.inputs) {
input.options.minimumTouchTime = 0;
}
}
}

/**
* @param {string} url
* @returns {Promise<chrome.tabs.Tab>}
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 @@ -2069,6 +2069,7 @@ export class Display extends EventDispatcher {
scanOnPenRelease: false,
preventTouchScrolling: false,
preventPenScrolling: false,
minimumTouchTime: 0,
},
}],
deepContentScan: scanningOptions.deepDomScan,
Expand Down
14 changes: 14 additions & 0 deletions ext/js/language/text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export class TextScanner extends EventDispatcher {

/** @type {boolean} */
this._touchTapValid = false;
/** @type {number} */
this._touchPressTime = 0;
/** @type {?number} */
this._primaryTouchIdentifier = null;
/** @type {boolean} */
Expand Down Expand Up @@ -723,6 +725,7 @@ export class TextScanner extends EventDispatcher {
this._preventNextMouseDown = false;
this._preventNextClick = false;
this._touchTapValid = true;
this._touchPressTime = Date.now();

const languageNotNull = this._language !== null ? this._language : '';
const selection = window.getSelection();
Expand Down Expand Up @@ -760,6 +763,7 @@ export class TextScanner extends EventDispatcher {
* @param {boolean} allowSearch
*/
_onPrimaryTouchEnd(e, x, y, allowSearch) {
const touchReleaseTime = Date.now();
this._primaryTouchIdentifier = null;
this._preventScroll = false;
this._preventNextClick = false;
Expand All @@ -770,6 +774,7 @@ export class TextScanner extends EventDispatcher {

const inputInfo = this._getMatchingInputGroupFromEvent('touch', 'touchEnd', e);
if (inputInfo === null || inputInfo.input === null) { return; }
if (touchReleaseTime - this._touchPressTime < inputInfo.input.minimumTouchTime) { return; }
if (inputInfo.input.scanOnTouchRelease || (inputInfo.input.scanOnTouchTap && this._touchTapValid)) {
void this._searchAtFromTouchEnd(x, y, inputInfo);
}
Expand Down Expand Up @@ -1493,6 +1498,7 @@ export class TextScanner extends EventDispatcher {
scanOnPenRelease: this._getInputBoolean(options.scanOnPenRelease),
preventTouchScrolling: this._getInputBoolean(options.preventTouchScrolling),
preventPenScrolling: this._getInputBoolean(options.preventPenScrolling),
minimumTouchTime: this._getInputNumber(options.minimumTouchTime),
};
}

Expand Down Expand Up @@ -1528,6 +1534,14 @@ export class TextScanner extends EventDispatcher {
return typeof value === 'boolean' && value;
}

/**
* @param {unknown} value
* @returns {number}
*/
_getInputNumber(value) {
return typeof value === 'number' ? value : -1;
}

/**
* @param {PointerEvent} e
* @returns {string}
Expand Down
5 changes: 5 additions & 0 deletions ext/js/pages/settings/scan-inputs-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class ScanInputsController {
scanOnPenRelease: false,
preventTouchScrolling: true,
preventPenScrolling: true,
minimumTouchTime: 0,
},
};
}
Expand Down Expand Up @@ -392,6 +393,10 @@ class ScanInputField {
const {property} = typeCheckbox.dataset;
typeCheckbox.dataset.setting = `scanning.inputs[${index}].${property}`;
}
for (const typeInput of /** @type {NodeListOf<HTMLElement>} */ (this._node.querySelectorAll('.scan-input-settings-input'))) {
const {property} = typeInput.dataset;
typeInput.dataset.setting = `scanning.inputs[${index}].${property}`;
}
}

/** */
Expand Down
4 changes: 4 additions & 0 deletions ext/templates-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@
<label class="checkbox"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.preventTouchScrolling"><span class="checkbox-body"><span class="checkbox-fill"></span><span class="checkbox-border"></span><span class="checkbox-check"></span></span></label>
<span>Prevent touch scrolling</span>
</label>
<label class="scan-input-input-item">
<span>Minimum Touch Time <span class="light">(in milliseconds)</span>:</span>
<label class="input"><input type="number" class="scan-input-settings-input" data-property="options.minimumTouchTime"></label>
</label>
</div>

<div class="scan-input-prefix-cell scan-input-options-cell scan-input-advanced-only" data-property="pen-options"><span>Pen options:</span></div>
Expand Down
5 changes: 4 additions & 1 deletion test/options-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ function createProfileOptionsUpdatedTestData1() {
scanOnPenRelease: false,
preventTouchScrolling: true,
preventPenScrolling: true,
minimumTouchTime: 0,
},
},
{
Expand All @@ -412,6 +413,7 @@ function createProfileOptionsUpdatedTestData1() {
scanOnPenRelease: false,
preventTouchScrolling: true,
preventPenScrolling: true,
minimumTouchTime: 0,
},
},
{
Expand All @@ -437,6 +439,7 @@ function createProfileOptionsUpdatedTestData1() {
scanOnPenRelease: false,
preventTouchScrolling: true,
preventPenScrolling: true,
minimumTouchTime: 0,
},
},
],
Expand Down Expand Up @@ -669,7 +672,7 @@ function createOptionsUpdatedTestData1() {
},
],
profileCurrent: 0,
version: 56,
version: 57,
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 @@ -228,6 +228,7 @@ export type ScanningInputOptions = {
scanOnPenRelease: boolean;
preventTouchScrolling: boolean;
preventPenScrolling: boolean;
minimumTouchTime: number;
};

export type ScanningPreventMiddleMouseOptions = {
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 @@ -68,6 +68,7 @@ export type InputOptions = {
scanOnPenRelease: boolean;
preventTouchScrolling: boolean;
preventPenScrolling: boolean;
minimumTouchTime: number;
};

export type SentenceParsingOptions = {
Expand All @@ -93,6 +94,7 @@ export type InputConfig = {
scanOnPenRelease: boolean;
preventTouchScrolling: boolean;
preventPenScrolling: boolean;
minimumTouchTime: number;
};

export type InputInfo = {
Expand Down

0 comments on commit 4197228

Please sign in to comment.