summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-04-26 21:11:43 -0400
committerGitHub <noreply@github.com>2021-04-26 21:11:43 -0400
commit763c6c76aa5bceb1eb929aa3a87bacf91e37407f (patch)
tree1624a83faeac46cc6d977ca0cd176c1f399b3da0
parent6f5ad490fb54b4d0431d56cc644c76d62213abd7 (diff)
Add scanTextAtCaret option (#1632)
-rw-r--r--ext/js/app/frontend.js17
-rw-r--r--ext/js/pages/settings/keyboard-shortcuts-controller.js1
-rw-r--r--ext/settings.html1
3 files changed, 13 insertions, 6 deletions
diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js
index e1b531d4..7913d7d8 100644
--- a/ext/js/app/frontend.js
+++ b/ext/js/app/frontend.js
@@ -79,7 +79,8 @@ class Frontend {
]);
this._hotkeyHandler.registerActions([
- ['scanSelectedText', this._onActionScanSelectedText.bind(this)]
+ ['scanSelectedText', this._onActionScanSelectedText.bind(this)],
+ ['scanTextAtCaret', this._onActionScanTextAtCaret.bind(this)]
]);
}
@@ -172,7 +173,11 @@ class Frontend {
// Action handlers
_onActionScanSelectedText() {
- this._scanSelectedText();
+ this._scanSelectedText(false);
+ }
+
+ _onActionScanTextAtCaret() {
+ this._scanSelectedText(true);
}
// API message handlers
@@ -679,19 +684,19 @@ class Frontend {
};
}
- async _scanSelectedText() {
- const range = this._getFirstNonEmptySelectionRange();
+ async _scanSelectedText(allowEmptyRange) {
+ const range = this._getFirstSelectionRange(allowEmptyRange);
if (range === null) { return false; }
const source = new TextSourceRange(range, range.toString(), null, null);
await this._textScanner.search(source, {focus: true, restoreSelection: true});
return true;
}
- _getFirstNonEmptySelectionRange() {
+ _getFirstSelectionRange(allowEmptyRange) {
const selection = window.getSelection();
for (let i = 0, ii = selection.rangeCount; i < ii; ++i) {
const range = selection.getRangeAt(i);
- if (range.toString().length > 0) {
+ if (range.toString().length > 0 || allowEmptyRange) {
return range;
}
}
diff --git a/ext/js/pages/settings/keyboard-shortcuts-controller.js b/ext/js/pages/settings/keyboard-shortcuts-controller.js
index aeff15b6..5e7b7783 100644
--- a/ext/js/pages/settings/keyboard-shortcuts-controller.js
+++ b/ext/js/pages/settings/keyboard-shortcuts-controller.js
@@ -52,6 +52,7 @@ class KeyboardShortcutController {
['playAudioFromSource', {scopes: new Set(['popup', 'search']), argument: {template: 'hotkey-argument-audio-source', default: 'jpod101'}}],
['copyHostSelection', {scopes: new Set(['popup'])}],
['scanSelectedText', {scopes: new Set(['web'])}],
+ ['scanTextAtCaret', {scopes: new Set(['web'])}],
['toggleOption', {scopes: new Set(['popup', 'search']), argument: {template: 'hotkey-argument-setting-path', default: ''}}]
]);
}
diff --git a/ext/settings.html b/ext/settings.html
index 732a96e2..7f9cc8ec 100644
--- a/ext/settings.html
+++ b/ext/settings.html
@@ -3227,6 +3227,7 @@
<option value="playAudioFromSource">Play audio from source</option>
<option value="copyHostSelection">Copy host window selection</option>
<option value="scanSelectedText">Scan selected text</option>
+ <option value="scanTextAtCaret">Scan text at caret</option>
<option value="toggleOption">Toggle option</option>
</select>
<div class="hotkey-list-item-action-argument-container"></div>