diff --git a/dev/Common/Globals.js b/dev/Common/Globals.js index 37551a4b5..aeed4cc19 100644 --- a/dev/Common/Globals.js +++ b/dev/Common/Globals.js @@ -32,6 +32,11 @@ export const fireEvent = (name, detail) => dispatchEvent(new CustomEvent(name, {detail:detail})), + formFieldFocused = () => doc.activeElement && doc.activeElement.matches('input,textarea'), + + registerShortcut = (keys, modifiers, scopes, method) => + shortcuts.add(keys, modifiers, scopes, () => formFieldFocused() ? true : method()), + addEventsListener = (element, events, fn, options) => events.forEach(event => element.addEventListener(event, fn, options)), diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 75855b6d5..bc654e85c 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -2,7 +2,7 @@ import { koArrayWithDestroy } from 'External/ko'; import { SaveSettingsStep } from 'Common/Enums'; import { ComposeType } from 'Common/EnumsUser'; -import { doc } from 'Common/Globals'; +import { registerShortcut } from 'Common/Globals'; import { arrayLength, pInt } from 'Common/Utils'; import { download, computedPaginatorHelper, showMessageComposer } from 'Common/UtilsUser'; @@ -449,15 +449,12 @@ export class ContactsPopupView extends AbstractViewPopup { onBuild(dom) { this.selector.init(dom.querySelector('.b-list-content'), ScopeContacts); - shortcuts.add('delete', '', ScopeContacts, () => { - if (doc.activeElement && doc.activeElement.matches('input,textarea')) { - return true; - } + registerShortcut('delete', '', ScopeContacts, () => { this.deleteCommand(); return false; }); - shortcuts.add('c,w', '', ScopeContacts, () => { + registerShortcut('c,w', '', ScopeContacts, () => { this.newMessageCommand(); return false; }); diff --git a/dev/View/User/MailBox/MessageList.js b/dev/View/User/MailBox/MessageList.js index fd1cf6ada..efe034a5b 100644 --- a/dev/View/User/MailBox/MessageList.js +++ b/dev/View/User/MailBox/MessageList.js @@ -6,7 +6,11 @@ import { ComposeType, FolderType, MessageSetAction } from 'Common/EnumsUser'; import { UNUSED_OPTION_VALUE } from 'Common/Consts'; -import { doc, leftPanelDisabled, moveAction, Settings, SettingsCapa, SettingsGet, fireEvent, addEventsListeners } from 'Common/Globals'; +import { doc, leftPanelDisabled, moveAction, + Settings, SettingsCapa, SettingsGet, + fireEvent, addEventsListeners, + registerShortcut +} from 'Common/Globals'; import { computedPaginatorHelper, showMessageComposer, populateMessageBody } from 'Common/UtilsUser'; import { FileInfo } from 'Common/File'; @@ -694,7 +698,7 @@ export class MailMessageList extends AbstractViewRight { // initShortcuts - shortcuts.add('enter,open', '', Scope.MessageList, () => { + registerShortcut('enter,open', '', Scope.MessageList, () => { if (MessageUserStore.message() && this.useAutoSelect()) { fireEvent('mailbox.message-view.toggle-full-screen'); return false; @@ -702,18 +706,18 @@ export class MailMessageList extends AbstractViewRight { }); // archive (zip) - shortcuts.add('z', '', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('z', '', [Scope.MessageList, Scope.MessageView], () => { this.archiveCommand(); return false; }); // delete - shortcuts.add('delete', 'shift', Scope.MessageList, () => { + registerShortcut('delete', 'shift', Scope.MessageList, () => { MessagelistUserStore.listCheckedOrSelected().length && this.deleteWithoutMoveCommand(); return false; }); -// shortcuts.add('3', 'shift', Scope.MessageList, () => { - shortcuts.add('delete', '', Scope.MessageList, () => { +// registerShortcut('3', 'shift', Scope.MessageList, () => { + registerShortcut('delete', '', Scope.MessageList, () => { MessagelistUserStore.listCheckedOrSelected().length && this.deleteCommand(); return false; }); @@ -731,18 +735,18 @@ export class MailMessageList extends AbstractViewRight { }); // write/compose (open compose popup) - shortcuts.add('w,c,new', '', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('w,c,new', '', [Scope.MessageList, Scope.MessageView], () => { showMessageComposer(); return false; }); // important - star/flag messages - shortcuts.add('i', '', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('i', '', [Scope.MessageList, Scope.MessageView], () => { this.flagMessagesFast(); return false; }); - shortcuts.add('t', '', [Scope.MessageList], () => { + registerShortcut('t', '', [Scope.MessageList], () => { let message = MessagelistUserStore.selectedMessage(); if (!message) { message = MessagelistUserStore.focusedMessage(); @@ -756,7 +760,7 @@ export class MailMessageList extends AbstractViewRight { }); // move - shortcuts.add('insert', '', Scope.MessageList, () => { + registerShortcut('insert', '', Scope.MessageList, () => { if (this.newMoveToFolder) { this.moveNewCommand(); } else { @@ -767,13 +771,13 @@ export class MailMessageList extends AbstractViewRight { }); // read - shortcuts.add('q', '', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('q', '', [Scope.MessageList, Scope.MessageView], () => { this.seenMessagesFast(true); return false; }); // unread - shortcuts.add('u', '', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('u', '', [Scope.MessageList, Scope.MessageView], () => { this.seenMessagesFast(false); return false; }); diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index c50bb8a7b..e76ed3293 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -22,7 +22,8 @@ import { SettingsCapa, getFullscreenElement, exitFullscreen, - fireEvent + fireEvent, + registerShortcut } from 'Common/Globals'; import { arrayLength } from 'Common/Utils'; @@ -379,7 +380,7 @@ export class MailMessageView extends AbstractViewRight { }); // reply - shortcuts.add('r,mailreply', '', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('r,mailreply', '', [Scope.MessageList, Scope.MessageView], () => { if (currentMessage()) { this.replyCommand(); return false; @@ -388,13 +389,13 @@ export class MailMessageView extends AbstractViewRight { }); // replyAll - shortcuts.add('a', '', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('a', '', [Scope.MessageList, Scope.MessageView], () => { if (currentMessage()) { this.replyAllCommand(); return false; } }); - shortcuts.add('mailreply', 'shift', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('mailreply', 'shift', [Scope.MessageList, Scope.MessageView], () => { if (currentMessage()) { this.replyAllCommand(); return false; @@ -402,7 +403,7 @@ export class MailMessageView extends AbstractViewRight { }); // forward - shortcuts.add('f,mailforward', '', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('f,mailforward', '', [Scope.MessageList, Scope.MessageView], () => { if (currentMessage()) { this.forwardCommand(); return false; @@ -410,7 +411,7 @@ export class MailMessageView extends AbstractViewRight { }); // message information - shortcuts.add('i', 'meta', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('i', 'meta', [Scope.MessageList, Scope.MessageView], () => { if (currentMessage()) { this.showFullInfo(!this.showFullInfo()); } @@ -418,7 +419,7 @@ export class MailMessageView extends AbstractViewRight { }); // toggle message blockquotes - shortcuts.add('b', '', [Scope.MessageList, Scope.MessageView], () => { + registerShortcut('b', '', [Scope.MessageList, Scope.MessageView], () => { const message = currentMessage(); if (message && message.body) { message.body.querySelectorAll('.rlBlockquoteSwitcher').forEach(node => node.click()); diff --git a/dev/View/User/SystemDropDown.js b/dev/View/User/SystemDropDown.js index 48301ced2..2f1927df8 100644 --- a/dev/View/User/SystemDropDown.js +++ b/dev/View/User/SystemDropDown.js @@ -13,7 +13,7 @@ import { KeyboardShortcutsHelpPopupView } from 'View/Popup/KeyboardShortcutsHelp import { AccountPopupView } from 'View/Popup/Account'; import { ContactsPopupView } from 'View/Popup/Contacts'; -import { doc, leftPanelDisabled, fireEvent, SettingsCapa } from 'Common/Globals'; +import { doc, leftPanelDisabled, fireEvent, SettingsCapa, registerShortcut } from 'Common/Globals'; import { ThemeStore } from 'Stores/Theme'; @@ -123,7 +123,7 @@ export class SystemDropDownUserView extends AbstractViewRight { } onBuild() { - shortcuts.add('m', '', [Scope.MessageList, Scope.MessageView, Scope.Settings], () => { + registerShortcut('m', '', [Scope.MessageList, Scope.MessageView, Scope.Settings], () => { if (!this.viewModelDom.hidden) { MessageUserStore.fullScreen(false); this.accountMenuDropdownTrigger(true); @@ -132,7 +132,7 @@ export class SystemDropDownUserView extends AbstractViewRight { }); // shortcuts help - shortcuts.add('?,f1,help', '', [Scope.MessageList, Scope.MessageView, Scope.Settings], () => { + registerShortcut('?,f1,help', '', [Scope.MessageList, Scope.MessageView, Scope.Settings], () => { if (!this.viewModelDom.hidden) { showScreenPopup(KeyboardShortcutsHelpPopupView); return false;