From 60987f46234960d8a473dd26f3f0b2767211ab9b Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 7 Mar 2022 13:47:03 +0100 Subject: [PATCH] Cleanup shortcuts scope handling --- dev/Common/Enums.js | 2 -- dev/Common/Globals.js | 26 ++++++++++++-------------- dev/Knoin/AbstractViews.js | 5 ++--- dev/Screen/User/MailBox.js | 2 +- dev/View/Popup/Plugin.js | 3 +-- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/dev/Common/Enums.js b/dev/Common/Enums.js index 1792149bc..f9ce77143 100644 --- a/dev/Common/Enums.js +++ b/dev/Common/Enums.js @@ -6,8 +6,6 @@ export const * @enum {string} */ Scope = { - All: 'all', - None: 'none', MessageList: 'MessageList', FolderList: 'FolderList', MessageView: 'MessageView', diff --git a/dev/Common/Globals.js b/dev/Common/Globals.js index aeed4cc19..45af6074e 100644 --- a/dev/Common/Globals.js +++ b/dev/Common/Globals.js @@ -1,7 +1,6 @@ import ko from 'ko'; -import { Scope } from 'Common/Enums'; -let keyScopeFake = Scope.All; +let keyScopeFake = 'all'; export const ScopeMenu = 'Menu', @@ -43,21 +42,20 @@ export const addEventsListeners = (element, events) => Object.entries(events).forEach(([event, fn]) => element.addEventListener(event, fn)), - // keys - keyScopeReal = ko.observable(Scope.All), + // keys / shortcuts + keyScopeReal = ko.observable('all'), keyScope = value => { - if (value) { - if (ScopeMenu !== value) { - keyScopeFake = value; - if (dropdownVisibility()) { - value = ScopeMenu; - } - } - keyScopeReal(value); - shortcuts.setScope(value); - } else { + if (!value) { return keyScopeFake; } + if (ScopeMenu !== value) { + keyScopeFake = value; + if (dropdownVisibility()) { + value = ScopeMenu; + } + } + keyScopeReal(value); + shortcuts.setScope(value); }; dropdownVisibility.subscribe(value => { diff --git a/dev/Knoin/AbstractViews.js b/dev/Knoin/AbstractViews.js index c724fd5e9..0b7e952b4 100644 --- a/dev/Knoin/AbstractViews.js +++ b/dev/Knoin/AbstractViews.js @@ -1,7 +1,6 @@ import ko from 'ko'; import { addObservablesTo, addComputablesTo, addSubscribablesTo } from 'External/ko'; -import { Scope } from 'Common/Enums'; import { keyScope, SettingsGet, leftPanelDisabled } from 'Common/Globals'; import { ViewType, showScreenPopup } from 'Knoin/Knoin'; @@ -16,8 +15,8 @@ class AbstractView { this.viewModelDom = null; this.keyScope = { - scope: Scope.None, - previous: Scope.None, + scope: 'none', + previous: 'none', set: function() { this.previous = keyScope(); keyScope(this.scope); diff --git a/dev/Screen/User/MailBox.js b/dev/Screen/User/MailBox.js index 211a45af5..181174d69 100644 --- a/dev/Screen/User/MailBox.js +++ b/dev/Screen/User/MailBox.js @@ -51,7 +51,7 @@ export class MailBoxUserScreen extends AbstractScreen { onShow() { this.updateWindowTitle(); - AppUserStore.focusedState(Scope.None); + AppUserStore.focusedState('none'); AppUserStore.focusedState(Scope.MessageList); ThemeStore.isMobile() && leftPanelDisabled(true); diff --git a/dev/View/Popup/Plugin.js b/dev/View/Popup/Plugin.js index ef4550ff1..2c899a367 100644 --- a/dev/View/Popup/Plugin.js +++ b/dev/View/Popup/Plugin.js @@ -1,6 +1,5 @@ import ko from 'ko'; -import { Scope } from 'Common/Enums'; import { getNotification, i18n } from 'Common/Translator'; import { arrayLength } from 'Common/Utils'; @@ -28,7 +27,7 @@ export class PluginPopupView extends AbstractViewPopup { hasConfiguration: () => 0 < this.config().length }); - this.keyScope.scope = Scope.All; + this.keyScope.scope = 'all'; decorateKoCommands(this, { saveCommand: self => self.hasConfiguration()