aboutsummaryrefslogtreecommitdiff
path: root/ext/fg
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg')
-rw-r--r--ext/fg/js/content-script-main.js7
-rw-r--r--ext/fg/js/frontend.js36
2 files changed, 41 insertions, 2 deletions
diff --git a/ext/fg/js/content-script-main.js b/ext/fg/js/content-script-main.js
index 80a600e2..42f95e24 100644
--- a/ext/fg/js/content-script-main.js
+++ b/ext/fg/js/content-script-main.js
@@ -17,6 +17,7 @@
/* global
* Frontend
+ * HotkeyHandler
* PopupFactory
* api
*/
@@ -31,6 +32,9 @@
throw new Error('Failed to get frameId');
}
+ const hotkeyHandler = new HotkeyHandler();
+ hotkeyHandler.prepare();
+
const popupFactory = new PopupFactory(frameId);
popupFactory.prepare();
@@ -42,7 +46,8 @@
parentFrameId: null,
useProxyPopup: false,
pageType: 'web',
- allowRootFramePopupProxy: true
+ allowRootFramePopupProxy: true,
+ hotkeyHandler
});
await frontend.prepare();
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index d789c4f0..e9b57eb5 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -19,6 +19,7 @@
* DocumentUtil
* TextScanner
* TextSourceElement
+ * TextSourceRange
* api
*/
@@ -32,7 +33,8 @@ class Frontend {
parentFrameId,
useProxyPopup,
allowRootFramePopupProxy,
- childrenSupported=true
+ childrenSupported=true,
+ hotkeyHandler
}) {
this._pageType = pageType;
this._popupFactory = popupFactory;
@@ -43,6 +45,7 @@ class Frontend {
this._useProxyPopup = useProxyPopup;
this._allowRootFramePopupProxy = allowRootFramePopupProxy;
this._childrenSupported = childrenSupported;
+ this._hotkeyHandler = hotkeyHandler;
this._popup = null;
this._disabledOverride = false;
this._options = null;
@@ -71,6 +74,10 @@ class Frontend {
['setAllVisibleOverride', {async: true, handler: this._onApiSetAllVisibleOverride.bind(this)}],
['clearAllVisibleOverride', {async: true, handler: this._onApiClearAllVisibleOverride.bind(this)}]
]);
+
+ this._hotkeyHandler.registerActions([
+ ['scanSelectedText', this._onActionScanSelectedText.bind(this)]
+ ]);
}
get canClearSelection() {
@@ -161,6 +168,12 @@ class Frontend {
this._signalFrontendReady(frameId);
}
+ // Action handlers
+
+ _onActionScanSelectedText() {
+ this._scanSelectedText();
+ }
+
// API message handlers
_onApiGetUrl() {
@@ -319,6 +332,8 @@ class Frontend {
const {scanning: scanningOptions, sentenceParsing: sentenceParsingOptions} = options;
this._options = options;
+ this._hotkeyHandler.setHotkeys('web', options.inputs.hotkeys);
+
await this._updatePopup();
const preventMiddleMouse = this._getPreventMiddleMouseValueForPageType(scanningOptions.preventMiddleMouse);
@@ -646,4 +661,23 @@ class Frontend {
detail: {documentTitle}
};
}
+
+ async _scanSelectedText() {
+ const range = this._getFirstNonEmptySelectionRange();
+ if (range === null) { return false; }
+ const source = new TextSourceRange(range, range.toString(), null, null);
+ await this._textScanner.search(source, {focus: true});
+ return true;
+ }
+
+ _getFirstNonEmptySelectionRange() {
+ const selection = window.getSelection();
+ for (let i = 0, ii = selection.rangeCount; i < ii; ++i) {
+ const range = selection.getRangeAt(i);
+ if (range.toString().length > 0) {
+ return range;
+ }
+ }
+ return null;
+ }
}