Skip to content

Commit

Permalink
Add option for scan without mouse move (#1252)
Browse files Browse the repository at this point in the history
* Add option for scan without mouse move

* Make tests happy
  • Loading branch information
Kuuuube authored Jul 21, 2024
1 parent 3eadb5d commit 850f9d1
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ext/data/schemas/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@
"matchTypePrefix",
"hidePopupOnCursorExit",
"hidePopupOnCursorExitDelay",
"normalizeCssZoom"
"normalizeCssZoom",
"scanWithoutMousemove"
],
"properties": {
"inputs": {
Expand Down Expand Up @@ -754,6 +755,10 @@
"normalizeCssZoom": {
"type": "boolean",
"default": true
},
"scanWithoutMousemove": {
"type": "boolean",
"default": true
}
}
},
Expand Down
1 change: 1 addition & 0 deletions ext/js/app/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export class Frontend {
preventMiddleMouse,
sentenceParsingOptions,
scanAltText: scanningOptions.scanAltText,
scanWithoutMousemove: scanningOptions.scanWithoutMousemove,
});
this._updateTextScannerEnabled();

Expand Down
11 changes: 11 additions & 0 deletions ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ export class OptionsUtil {
this._updateVersion44,
this._updateVersion45,
this._updateVersion46,
this._updateVersion47,
];
/* eslint-enable @typescript-eslint/unbound-method */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
Expand Down Expand Up @@ -1423,6 +1424,16 @@ export class OptionsUtil {
}
}

/**
* - Added scanning.scanWithoutMousemove
* @type {import('options-util').UpdateFunction}
*/
async _updateVersion47(options) {
for (const profile of options.profiles) {
profile.options.scanning.scanWithoutMousemove = true;
}
}

/**
* @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 @@ -465,6 +465,7 @@ export class Display extends EventDispatcher {
matchTypePrefix: false,
sentenceParsingOptions,
scanAltText: scanningOptions.scanAltText,
scanWithoutMousemove: scanningOptions.scanWithoutMousemove,
},
});

Expand Down
9 changes: 8 additions & 1 deletion ext/js/language/text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export class TextScanner extends EventDispatcher {
sentenceParsingOptions,
matchTypePrefix,
scanAltText,
scanWithoutMousemove,
}) {
if (Array.isArray(inputs)) {
this._inputs = inputs.map((input) => this._convertInput(input));
Expand Down Expand Up @@ -295,6 +296,9 @@ export class TextScanner extends EventDispatcher {
if (typeof scanAltText === 'boolean') {
this._scanAltText = scanAltText;
}
if (typeof scanWithoutMousemove === 'boolean') {
this._scanWithoutMousemove = scanWithoutMousemove;
}
if (typeof sentenceParsingOptions === 'object' && sentenceParsingOptions !== null) {
const {scanExtent, terminationCharacterMode, terminationCharacters} = sentenceParsingOptions;
if (typeof scanExtent === 'number') {
Expand Down Expand Up @@ -1117,7 +1121,10 @@ export class TextScanner extends EventDispatcher {
} else if (this._arePointerEventsSupported()) {
eventListenerInfos = this._getPointerEventListeners(capture);
} else {
eventListenerInfos = [...this._getMouseEventListeners(capture), ...this._getKeyboardEventListeners(capture)];
eventListenerInfos = [...this._getMouseEventListeners(capture)];
if (this._scanWithoutMousemove) {
eventListenerInfos.push(...this._getKeyboardEventListeners(capture));
}
if (this._touchInputEnabled) {
eventListenerInfos.push(...this._getTouchEventListeners(capture));
}
Expand Down
9 changes: 9 additions & 0 deletions ext/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,15 @@ <h1>Yomitan Settings</h1>
<input type="number" data-setting="scanning.delay" min="0">
</div>
</div></div>
<div class="settings-item advanced-only"><div class="settings-item-inner settings-item-inner-wrappable">
<div class="settings-item-left">
<div class="settings-item-label">Scan without mouse move</div>
<div class="settings-item-description">Allow scanning words under the pointer without the pointer being in motion.</div>
</div>
<div class="settings-item-right">
<label class="toggle"><input type="checkbox" data-setting="scanning.scanWithoutMousemove"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label>
</div>
</div></div>
<div class="settings-item"><div class="settings-item-inner">
<div class="settings-item-left">
<div class="settings-item-label">Select matched text</div>
Expand Down
3 changes: 2 additions & 1 deletion test/options-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ function createProfileOptionsUpdatedTestData1() {
onSearchPages: false,
onSearchQuery: false,
},
scanWithoutMousemove: true,
inputs: [
{
include: 'shift',
Expand Down Expand Up @@ -636,7 +637,7 @@ function createOptionsUpdatedTestData1() {
},
],
profileCurrent: 0,
version: 46,
version: 47,
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 @@ -195,6 +195,7 @@ export type ScanningOptions = {
hidePopupOnCursorExitDelay: number;
normalizeCssZoom: boolean;
scanAltText: boolean;
scanWithoutMousemove: boolean;
};

export type ScanningInput = {
Expand Down
1 change: 1 addition & 0 deletions types/ext/text-scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type Options = {
matchTypePrefix?: boolean;
sentenceParsingOptions?: SentenceParsingOptions;
scanAltText?: boolean;
scanWithoutMousemove?: boolean;
};

export type InputOptionsOuter = {
Expand Down

0 comments on commit 850f9d1

Please sign in to comment.