aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-16 14:54:35 -0500
committerGitHub <noreply@github.com>2021-01-16 14:54:35 -0500
commit0ac35771192adb87d76809aff171d60a5d0018c3 (patch)
treecbe132a385a5d6800706e3d2c0f13665303145dc /ext/bg
parenta0f8c8b95ca41502a8fd68fe32aa29cdd7f46ac1 (diff)
Refactor hotkey handling (#1250)
* Create HotkeyHandler * Update Display to use HotkeyHandler
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/search.js28
-rw-r--r--ext/bg/search.html1
2 files changed, 15 insertions, 14 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 00148418..5963c03b 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -44,7 +44,7 @@ class DisplaySearch extends Display {
});
this.autoPlayAudioDelay = 0;
- this.registerActions([
+ this.hotkeyHandler.registerActions([
['focusSearchBox', this._onActionFocusSearchBox.bind(this)]
]);
}
@@ -73,6 +73,7 @@ class DisplaySearch extends Display {
window.addEventListener('copy', this._onCopy.bind(this));
this._clipboardMonitor.on('change', this._onExternalSearchUpdate.bind(this));
this._clipboardMonitorEnableCheckbox.addEventListener('change', this._onClipboardMonitorEnableChange.bind(this));
+ this.hotkeyHandler.on('keydownNonHotkey', this._onKeyDown.bind(this));
this._onModeChange();
@@ -81,19 +82,6 @@ class DisplaySearch extends Display {
this._isPrepared = true;
}
- onKeyDown(e) {
- if (
- !super.onKeyDown(e) &&
- document.activeElement !== this._queryInput &&
- !e.ctrlKey &&
- !e.metaKey &&
- !e.altKey &&
- e.key.length === 1
- ) {
- this._queryInput.focus({preventScroll: true});
- }
- }
-
postProcessQuery(query) {
if (this._wanakanaEnabled) {
try {
@@ -115,6 +103,18 @@ class DisplaySearch extends Display {
// Private
+ _onKeyDown(e) {
+ if (
+ document.activeElement !== this._queryInput &&
+ !e.ctrlKey &&
+ !e.metaKey &&
+ !e.altKey &&
+ e.key.length === 1
+ ) {
+ this._queryInput.focus({preventScroll: true});
+ }
+ }
+
async _onOptionsUpdated() {
await this.updateOptions();
const query = this._queryInput.value;
diff --git a/ext/bg/search.html b/ext/bg/search.html
index 43f9f7eb..dae657e8 100644
--- a/ext/bg/search.html
+++ b/ext/bg/search.html
@@ -92,6 +92,7 @@
<script src="/mixed/js/display-history.js"></script>
<script src="/mixed/js/display-notification.js"></script>
<script src="/mixed/js/dynamic-loader.js"></script>
+<script src="/mixed/js/hotkey-handler.js"></script>
<script src="/mixed/js/media-loader.js"></script>
<script src="/mixed/js/scroll.js"></script>
<script src="/mixed/js/text-scanner.js"></script>