Add scanTextAtCaret option (#1632)
This commit is contained in:
parent
6f5ad490fb
commit
763c6c76aa
@ -79,7 +79,8 @@ class Frontend {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
this._hotkeyHandler.registerActions([
|
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
|
// Action handlers
|
||||||
|
|
||||||
_onActionScanSelectedText() {
|
_onActionScanSelectedText() {
|
||||||
this._scanSelectedText();
|
this._scanSelectedText(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onActionScanTextAtCaret() {
|
||||||
|
this._scanSelectedText(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// API message handlers
|
// API message handlers
|
||||||
@ -679,19 +684,19 @@ class Frontend {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async _scanSelectedText() {
|
async _scanSelectedText(allowEmptyRange) {
|
||||||
const range = this._getFirstNonEmptySelectionRange();
|
const range = this._getFirstSelectionRange(allowEmptyRange);
|
||||||
if (range === null) { return false; }
|
if (range === null) { return false; }
|
||||||
const source = new TextSourceRange(range, range.toString(), null, null);
|
const source = new TextSourceRange(range, range.toString(), null, null);
|
||||||
await this._textScanner.search(source, {focus: true, restoreSelection: true});
|
await this._textScanner.search(source, {focus: true, restoreSelection: true});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_getFirstNonEmptySelectionRange() {
|
_getFirstSelectionRange(allowEmptyRange) {
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
for (let i = 0, ii = selection.rangeCount; i < ii; ++i) {
|
for (let i = 0, ii = selection.rangeCount; i < ii; ++i) {
|
||||||
const range = selection.getRangeAt(i);
|
const range = selection.getRangeAt(i);
|
||||||
if (range.toString().length > 0) {
|
if (range.toString().length > 0 || allowEmptyRange) {
|
||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ class KeyboardShortcutController {
|
|||||||
['playAudioFromSource', {scopes: new Set(['popup', 'search']), argument: {template: 'hotkey-argument-audio-source', default: 'jpod101'}}],
|
['playAudioFromSource', {scopes: new Set(['popup', 'search']), argument: {template: 'hotkey-argument-audio-source', default: 'jpod101'}}],
|
||||||
['copyHostSelection', {scopes: new Set(['popup'])}],
|
['copyHostSelection', {scopes: new Set(['popup'])}],
|
||||||
['scanSelectedText', {scopes: new Set(['web'])}],
|
['scanSelectedText', {scopes: new Set(['web'])}],
|
||||||
|
['scanTextAtCaret', {scopes: new Set(['web'])}],
|
||||||
['toggleOption', {scopes: new Set(['popup', 'search']), argument: {template: 'hotkey-argument-setting-path', default: ''}}]
|
['toggleOption', {scopes: new Set(['popup', 'search']), argument: {template: 'hotkey-argument-setting-path', default: ''}}]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -3227,6 +3227,7 @@
|
|||||||
<option value="playAudioFromSource">Play audio from source</option>
|
<option value="playAudioFromSource">Play audio from source</option>
|
||||||
<option value="copyHostSelection">Copy host window selection</option>
|
<option value="copyHostSelection">Copy host window selection</option>
|
||||||
<option value="scanSelectedText">Scan selected text</option>
|
<option value="scanSelectedText">Scan selected text</option>
|
||||||
|
<option value="scanTextAtCaret">Scan text at caret</option>
|
||||||
<option value="toggleOption">Toggle option</option>
|
<option value="toggleOption">Toggle option</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="hotkey-list-item-action-argument-container"></div>
|
<div class="hotkey-list-item-action-argument-container"></div>
|
||||||
|
Loading…
Reference in New Issue
Block a user