From 266c8c3a3f0d6f8c39832bfdc0cc88b88c2b710b Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Tue, 14 May 2024 13:02:33 -0400 Subject: Make Scan selected text lazy and add Scan text at selection (#915) * Add Scan selected text lazy * Remove extra spaces * Improve naming * Use disallowExpandSelection instead of "lazy" * Use "keyword arguments" for _scanSelectedText * Revert Use "keyword arguments" for _scanSelectedText --- ext/js/app/frontend.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'ext/js/app') diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index 4c0faef1..cc71311d 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -119,6 +119,7 @@ export class Frontend { this._hotkeyHandler.registerActions([ ['scanSelectedText', this._onActionScanSelectedText.bind(this)], + ['scanTextAtSelection', this._onActionScanTextAtSelection.bind(this)], ['scanTextAtCaret', this._onActionScanTextAtCaret.bind(this)] ]); /* eslint-enable @stylistic/no-multi-spaces */ @@ -256,14 +257,21 @@ export class Frontend { * @returns {void} */ _onActionScanSelectedText() { - void this._scanSelectedText(false); + void this._scanSelectedText(false, true); + } + + /** + * @returns {void} + */ + _onActionScanTextAtSelection() { + void this._scanSelectedText(false, false); } /** * @returns {void} */ _onActionScanTextAtCaret() { - void this._scanSelectedText(true); + void this._scanSelectedText(true, false); } // API message handlers @@ -919,12 +927,13 @@ export class Frontend { /** * @param {boolean} allowEmptyRange + * @param {boolean} disallowExpandSelection * @returns {Promise} */ - async _scanSelectedText(allowEmptyRange) { + async _scanSelectedText(allowEmptyRange, disallowExpandSelection) { const range = this._getFirstSelectionRange(allowEmptyRange); if (range === null) { return false; } - const source = TextSourceRange.create(range); + const source = disallowExpandSelection ? TextSourceRange.createLazy(range) : TextSourceRange.create(range); await this._textScanner.search(source, {focus: true, restoreSelection: true}); return true; } -- cgit v1.2.3