summaryrefslogtreecommitdiff
path: root/ext/js/app
diff options
context:
space:
mode:
authorKuuuube <61125188+Kuuuube@users.noreply.github.com>2024-05-14 13:02:33 -0400
committerGitHub <noreply@github.com>2024-05-14 17:02:33 +0000
commit266c8c3a3f0d6f8c39832bfdc0cc88b88c2b710b (patch)
tree360198d216a15b828714a40435a6139b28c28d2b /ext/js/app
parentba288277a5e73026f7b0c07d993aa00a5e66c332 (diff)
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
Diffstat (limited to 'ext/js/app')
-rw-r--r--ext/js/app/frontend.js17
1 files changed, 13 insertions, 4 deletions
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<boolean>}
*/
- 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;
}