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

Allow scanning without moving mouse from clicking #1538

Merged
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
2 changes: 0 additions & 2 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -2011,8 +2011,6 @@ export class Display extends EventDispatcher {
getSearchContext: this._getSearchContext.bind(this),
searchTerms: true,
searchKanji: false,
searchOnClick: true,
searchOnClickOnly: true,
textSourceGenerator: this._textSourceGenerator,
});
this._contentTextScanner.includeSelector = '.click-scannable,.click-scannable *';
Expand Down
1 change: 0 additions & 1 deletion ext/js/display/query-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export class QueryParser extends EventDispatcher {
getSearchContext,
searchTerms: true,
searchKanji: false,
searchOnClick: true,
textSourceGenerator,
});
/** @type {?(import('../language/ja/japanese-wanakana.js'))} */
Expand Down
68 changes: 4 additions & 64 deletions ext/js/language/text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export class TextScanner extends EventDispatcher {
ignorePoint = null,
searchTerms = false,
searchKanji = false,
searchOnClick = false,
searchOnClickOnly = false,
textSourceGenerator,
}) {
super();
Expand All @@ -58,10 +56,6 @@ export class TextScanner extends EventDispatcher {
this._searchTerms = searchTerms;
/** @type {boolean} */
this._searchKanji = searchKanji;
/** @type {boolean} */
this._searchOnClick = searchOnClick;
/** @type {boolean} */
this._searchOnClickOnly = searchOnClickOnly;
/** @type {import('../dom/text-source-generator').TextSourceGenerator} */
this._textSourceGenerator = textSourceGenerator;

Expand Down Expand Up @@ -662,7 +656,6 @@ export class TextScanner extends EventDispatcher {

switch (e.button) {
case 0: // Primary
if (this._searchOnClick) { this._resetPreventNextClickScan(); }
this._scanTimerClear();
this._triggerClear('mousedown');
break;
Expand All @@ -674,6 +667,8 @@ export class TextScanner extends EventDispatcher {
}
break;
}

this._onMouseMove(e);
}

/** */
Expand All @@ -694,28 +689,7 @@ export class TextScanner extends EventDispatcher {
return false;
}

if (this._searchOnClick) {
this._onSearchClick(e);
}
}

/**
* @param {MouseEvent} e
*/
_onSearchClick(e) {
const preventNextClickScan = this._preventNextClickScan;
this._preventNextClickScan = false;
if (this._preventNextClickScanTimer !== null) {
clearTimeout(this._preventNextClickScanTimer);
this._preventNextClickScanTimer = null;
}

if (preventNextClickScan) { return; }

const modifiers = getActiveModifiersAndButtons(e);
const modifierKeys = getActiveModifiers(e);
const inputInfo = this._createInputInfo(null, 'mouse', 'click', false, modifiers, modifierKeys);
void this._searchAt(e.clientX, e.clientY, inputInfo);
this._onMouseMove(e);
}

/** */
Expand Down Expand Up @@ -1141,9 +1115,7 @@ export class TextScanner extends EventDispatcher {
const capture = true;
/** @type {import('event-listener-collection').AddEventListenerArgs[]} */
let eventListenerInfos;
if (this._searchOnClickOnly) {
eventListenerInfos = this._getMouseClickOnlyEventListeners(capture);
} else if (this._arePointerEventsSupported()) {
if (this._arePointerEventsSupported()) {
eventListenerInfos = this._getPointerEventListeners(capture);
} else {
eventListenerInfos = [...this._getMouseEventListeners(capture)];
Expand All @@ -1154,9 +1126,6 @@ export class TextScanner extends EventDispatcher {
eventListenerInfos.push(...this._getTouchEventListeners(capture));
}
}
if (this._searchOnClick) {
eventListenerInfos.push(...this._getMouseClickOnlyEventListeners2(capture));
}

eventListenerInfos.push(this._getSelectionChangeCheckUserSelectionListener());

Expand Down Expand Up @@ -1223,35 +1192,6 @@ export class TextScanner extends EventDispatcher {
];
}

/**
* @param {boolean} capture
* @returns {import('event-listener-collection').AddEventListenerArgs[]}
*/
_getMouseClickOnlyEventListeners(capture) {
return [
[this._node, 'click', this._onClick.bind(this), capture],
];
}

/**
* @param {boolean} capture
* @returns {import('event-listener-collection').AddEventListenerArgs[]}
*/
_getMouseClickOnlyEventListeners2(capture) {
const {documentElement} = document;
/** @type {import('event-listener-collection').AddEventListenerArgs[]} */
const entries = [
[document, 'selectionchange', this._onSelectionChange.bind(this)],
];
if (documentElement !== null) {
entries.push([documentElement, 'mousedown', this._onSearchClickMouseDown.bind(this), capture]);
if (this._touchInputEnabled) {
entries.push([documentElement, 'touchstart', this._onSearchClickTouchStart.bind(this), {passive: true, capture}]);
}
}
return entries;
}

/**
* @returns {import('event-listener-collection').AddEventListenerArgs}
*/
Expand Down
2 changes: 0 additions & 2 deletions types/ext/text-scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ export type ConstructorDetails = {
ignorePoint?: ((x: number, y: number) => Promise<boolean>) | null;
searchTerms?: boolean;
searchKanji?: boolean;
searchOnClick?: boolean;
searchOnClickOnly?: boolean;
textSourceGenerator: TextSourceGenerator;
};

Expand Down
Loading