Resolve #265 regarding shortcuts in certain input fields.

As we want other shortcuts do work in input fields (which couldn't in previous releases).
This commit is contained in:
the-djmaze 2022-03-04 14:43:58 +01:00
parent 54f48fbe4d
commit a503329b77
5 changed files with 35 additions and 28 deletions

View file

@ -32,6 +32,11 @@ export const
fireEvent = (name, detail) => dispatchEvent(new CustomEvent(name, {detail:detail})), 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) => addEventsListener = (element, events, fn, options) =>
events.forEach(event => element.addEventListener(event, fn, options)), events.forEach(event => element.addEventListener(event, fn, options)),

View file

@ -2,7 +2,7 @@ import { koArrayWithDestroy } from 'External/ko';
import { SaveSettingsStep } from 'Common/Enums'; import { SaveSettingsStep } from 'Common/Enums';
import { ComposeType } from 'Common/EnumsUser'; import { ComposeType } from 'Common/EnumsUser';
import { doc } from 'Common/Globals'; import { registerShortcut } from 'Common/Globals';
import { arrayLength, pInt } from 'Common/Utils'; import { arrayLength, pInt } from 'Common/Utils';
import { download, computedPaginatorHelper, showMessageComposer } from 'Common/UtilsUser'; import { download, computedPaginatorHelper, showMessageComposer } from 'Common/UtilsUser';
@ -449,15 +449,12 @@ export class ContactsPopupView extends AbstractViewPopup {
onBuild(dom) { onBuild(dom) {
this.selector.init(dom.querySelector('.b-list-content'), ScopeContacts); this.selector.init(dom.querySelector('.b-list-content'), ScopeContacts);
shortcuts.add('delete', '', ScopeContacts, () => { registerShortcut('delete', '', ScopeContacts, () => {
if (doc.activeElement && doc.activeElement.matches('input,textarea')) {
return true;
}
this.deleteCommand(); this.deleteCommand();
return false; return false;
}); });
shortcuts.add('c,w', '', ScopeContacts, () => { registerShortcut('c,w', '', ScopeContacts, () => {
this.newMessageCommand(); this.newMessageCommand();
return false; return false;
}); });

View file

@ -6,7 +6,11 @@ import { ComposeType, FolderType, MessageSetAction } from 'Common/EnumsUser';
import { UNUSED_OPTION_VALUE } from 'Common/Consts'; 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 { computedPaginatorHelper, showMessageComposer, populateMessageBody } from 'Common/UtilsUser';
import { FileInfo } from 'Common/File'; import { FileInfo } from 'Common/File';
@ -694,7 +698,7 @@ export class MailMessageList extends AbstractViewRight {
// initShortcuts // initShortcuts
shortcuts.add('enter,open', '', Scope.MessageList, () => { registerShortcut('enter,open', '', Scope.MessageList, () => {
if (MessageUserStore.message() && this.useAutoSelect()) { if (MessageUserStore.message() && this.useAutoSelect()) {
fireEvent('mailbox.message-view.toggle-full-screen'); fireEvent('mailbox.message-view.toggle-full-screen');
return false; return false;
@ -702,18 +706,18 @@ export class MailMessageList extends AbstractViewRight {
}); });
// archive (zip) // archive (zip)
shortcuts.add('z', '', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('z', '', [Scope.MessageList, Scope.MessageView], () => {
this.archiveCommand(); this.archiveCommand();
return false; return false;
}); });
// delete // delete
shortcuts.add('delete', 'shift', Scope.MessageList, () => { registerShortcut('delete', 'shift', Scope.MessageList, () => {
MessagelistUserStore.listCheckedOrSelected().length && this.deleteWithoutMoveCommand(); MessagelistUserStore.listCheckedOrSelected().length && this.deleteWithoutMoveCommand();
return false; return false;
}); });
// shortcuts.add('3', 'shift', Scope.MessageList, () => { // registerShortcut('3', 'shift', Scope.MessageList, () => {
shortcuts.add('delete', '', Scope.MessageList, () => { registerShortcut('delete', '', Scope.MessageList, () => {
MessagelistUserStore.listCheckedOrSelected().length && this.deleteCommand(); MessagelistUserStore.listCheckedOrSelected().length && this.deleteCommand();
return false; return false;
}); });
@ -731,18 +735,18 @@ export class MailMessageList extends AbstractViewRight {
}); });
// write/compose (open compose popup) // write/compose (open compose popup)
shortcuts.add('w,c,new', '', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('w,c,new', '', [Scope.MessageList, Scope.MessageView], () => {
showMessageComposer(); showMessageComposer();
return false; return false;
}); });
// important - star/flag messages // important - star/flag messages
shortcuts.add('i', '', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('i', '', [Scope.MessageList, Scope.MessageView], () => {
this.flagMessagesFast(); this.flagMessagesFast();
return false; return false;
}); });
shortcuts.add('t', '', [Scope.MessageList], () => { registerShortcut('t', '', [Scope.MessageList], () => {
let message = MessagelistUserStore.selectedMessage(); let message = MessagelistUserStore.selectedMessage();
if (!message) { if (!message) {
message = MessagelistUserStore.focusedMessage(); message = MessagelistUserStore.focusedMessage();
@ -756,7 +760,7 @@ export class MailMessageList extends AbstractViewRight {
}); });
// move // move
shortcuts.add('insert', '', Scope.MessageList, () => { registerShortcut('insert', '', Scope.MessageList, () => {
if (this.newMoveToFolder) { if (this.newMoveToFolder) {
this.moveNewCommand(); this.moveNewCommand();
} else { } else {
@ -767,13 +771,13 @@ export class MailMessageList extends AbstractViewRight {
}); });
// read // read
shortcuts.add('q', '', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('q', '', [Scope.MessageList, Scope.MessageView], () => {
this.seenMessagesFast(true); this.seenMessagesFast(true);
return false; return false;
}); });
// unread // unread
shortcuts.add('u', '', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('u', '', [Scope.MessageList, Scope.MessageView], () => {
this.seenMessagesFast(false); this.seenMessagesFast(false);
return false; return false;
}); });

View file

@ -22,7 +22,8 @@ import {
SettingsCapa, SettingsCapa,
getFullscreenElement, getFullscreenElement,
exitFullscreen, exitFullscreen,
fireEvent fireEvent,
registerShortcut
} from 'Common/Globals'; } from 'Common/Globals';
import { arrayLength } from 'Common/Utils'; import { arrayLength } from 'Common/Utils';
@ -379,7 +380,7 @@ export class MailMessageView extends AbstractViewRight {
}); });
// reply // reply
shortcuts.add('r,mailreply', '', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('r,mailreply', '', [Scope.MessageList, Scope.MessageView], () => {
if (currentMessage()) { if (currentMessage()) {
this.replyCommand(); this.replyCommand();
return false; return false;
@ -388,13 +389,13 @@ export class MailMessageView extends AbstractViewRight {
}); });
// replyAll // replyAll
shortcuts.add('a', '', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('a', '', [Scope.MessageList, Scope.MessageView], () => {
if (currentMessage()) { if (currentMessage()) {
this.replyAllCommand(); this.replyAllCommand();
return false; return false;
} }
}); });
shortcuts.add('mailreply', 'shift', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('mailreply', 'shift', [Scope.MessageList, Scope.MessageView], () => {
if (currentMessage()) { if (currentMessage()) {
this.replyAllCommand(); this.replyAllCommand();
return false; return false;
@ -402,7 +403,7 @@ export class MailMessageView extends AbstractViewRight {
}); });
// forward // forward
shortcuts.add('f,mailforward', '', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('f,mailforward', '', [Scope.MessageList, Scope.MessageView], () => {
if (currentMessage()) { if (currentMessage()) {
this.forwardCommand(); this.forwardCommand();
return false; return false;
@ -410,7 +411,7 @@ export class MailMessageView extends AbstractViewRight {
}); });
// message information // message information
shortcuts.add('i', 'meta', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('i', 'meta', [Scope.MessageList, Scope.MessageView], () => {
if (currentMessage()) { if (currentMessage()) {
this.showFullInfo(!this.showFullInfo()); this.showFullInfo(!this.showFullInfo());
} }
@ -418,7 +419,7 @@ export class MailMessageView extends AbstractViewRight {
}); });
// toggle message blockquotes // toggle message blockquotes
shortcuts.add('b', '', [Scope.MessageList, Scope.MessageView], () => { registerShortcut('b', '', [Scope.MessageList, Scope.MessageView], () => {
const message = currentMessage(); const message = currentMessage();
if (message && message.body) { if (message && message.body) {
message.body.querySelectorAll('.rlBlockquoteSwitcher').forEach(node => node.click()); message.body.querySelectorAll('.rlBlockquoteSwitcher').forEach(node => node.click());

View file

@ -13,7 +13,7 @@ import { KeyboardShortcutsHelpPopupView } from 'View/Popup/KeyboardShortcutsHelp
import { AccountPopupView } from 'View/Popup/Account'; import { AccountPopupView } from 'View/Popup/Account';
import { ContactsPopupView } from 'View/Popup/Contacts'; 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'; import { ThemeStore } from 'Stores/Theme';
@ -123,7 +123,7 @@ export class SystemDropDownUserView extends AbstractViewRight {
} }
onBuild() { onBuild() {
shortcuts.add('m', '', [Scope.MessageList, Scope.MessageView, Scope.Settings], () => { registerShortcut('m', '', [Scope.MessageList, Scope.MessageView, Scope.Settings], () => {
if (!this.viewModelDom.hidden) { if (!this.viewModelDom.hidden) {
MessageUserStore.fullScreen(false); MessageUserStore.fullScreen(false);
this.accountMenuDropdownTrigger(true); this.accountMenuDropdownTrigger(true);
@ -132,7 +132,7 @@ export class SystemDropDownUserView extends AbstractViewRight {
}); });
// shortcuts help // 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) { if (!this.viewModelDom.hidden) {
showScreenPopup(KeyboardShortcutsHelpPopupView); showScreenPopup(KeyboardShortcutsHelpPopupView);
return false; return false;