From 0ac35771192adb87d76809aff171d60a5d0018c3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 16 Jan 2021 14:54:35 -0500 Subject: Refactor hotkey handling (#1250) * Create HotkeyHandler * Update Display to use HotkeyHandler --- ext/bg/js/search.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'ext/bg/js/search.js') 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; -- cgit v1.2.3