From cbc5ab5696a64fe10d5a37d25cc6e87d8d44481f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 18 Jan 2021 15:23:49 -0500 Subject: [PATCH] Hotkey help controller (#1272) * Create HotkeyHelpController * Expose getAllTemplates * Update hotkeys on the context page * Update hotkeys on the display pages * Fix display issue where a hotkey used to be defined but no longer is --- ext/bg/context.html | 11 ++- ext/bg/js/context-main.js | 16 +++ ext/bg/search.html | 2 + ext/fg/float.html | 8 +- ext/mixed/display-templates.html | 22 ++--- ext/mixed/js/display-generator.js | 11 ++- ext/mixed/js/display.js | 9 +- ext/mixed/js/hotkey-help-controller.js | 120 +++++++++++++++++++++++ ext/mixed/js/html-template-collection.js | 4 + 9 files changed, 183 insertions(+), 20 deletions(-) create mode 100644 ext/mixed/js/hotkey-help-controller.js diff --git a/ext/bg/context.html b/ext/bg/context.html index 4b2bcb8c..afd89207 100644 --- a/ext/bg/context.html +++ b/ext/bg/context.html @@ -30,9 +30,9 @@ - - - + + + @@ -42,7 +42,7 @@ Enable content scanning - Options + Settings Search @@ -57,6 +57,9 @@ + + + diff --git a/ext/bg/js/context-main.js b/ext/bg/js/context-main.js index 839b534e..65853514 100644 --- a/ext/bg/js/context-main.js +++ b/ext/bg/js/context-main.js @@ -16,6 +16,7 @@ */ /* global + * HotkeyHelpController * api */ @@ -35,6 +36,8 @@ class DisplayController { const optionsFull = await api.optionsGetFull(); this._optionsFull = optionsFull; + this._setupHotkeys(); + const optionsPageUrl = optionsFull.global.useSettingsV2 ? '/bg/settings2.html' : manifest.options_ui.page; this._setupButtonEvents('.action-open-settings', 'openSettingsPage', chrome.runtime.getURL(optionsPageUrl)); @@ -99,6 +102,19 @@ class DisplayController { } } + async _setupHotkeys() { + const hotkeyHelpController = new HotkeyHelpController(); + await hotkeyHelpController.prepare(); + + const {profiles, profileCurrent} = this._optionsFull; + const primaryProfile = (profileCurrent >= 0 && profileCurrent < profiles.length) ? profiles[profileCurrent] : null; + if (primaryProfile !== null) { + hotkeyHelpController.setOptions(primaryProfile.options); + } + + hotkeyHelpController.setupNode(document.documentElement); + } + _updateProfileSelect(profiles, profileCurrent) { const select = document.querySelector('#profile-select'); const optionGroup = document.querySelector('#profile-select-option-group'); diff --git a/ext/bg/search.html b/ext/bg/search.html index f8e4d21c..4a0cac58 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -94,6 +94,8 @@ + + diff --git a/ext/fg/float.html b/ext/fg/float.html index 52fe3e66..512818bd 100644 --- a/ext/fg/float.html +++ b/ext/fg/float.html @@ -66,11 +66,11 @@