From 97eff2b113fd9f544f5e66e099cce1a4a4263606 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Mon, 18 Apr 2022 11:08:15 +0200 Subject: [PATCH] fix keybindings --- .../web/src/commands/CommandListener.svelte | 19 ++++++++++++++++++- packages/web/src/commands/registerCommand.ts | 1 + packages/web/src/commands/stdCommands.ts | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/web/src/commands/CommandListener.svelte b/packages/web/src/commands/CommandListener.svelte index 885de4b1..180cc875 100644 --- a/packages/web/src/commands/CommandListener.svelte +++ b/packages/web/src/commands/CommandListener.svelte @@ -13,7 +13,7 @@ keyText += e.key; const commandsValue = get(commandsCustomized); - const commandsFiltered: any = Object.values(commandsValue).filter( + let commandsFiltered: any = Object.values(commandsValue).filter( (x: any) => x.keyText && resolveKeyText(x.keyText) @@ -34,7 +34,20 @@ e.stopPropagation(); } + if ( + commandsFiltered.length > 1 && + commandsFiltered.find(x => x.systemCommand) && + commandsFiltered.find(x => !x.systemCommand) + ) { + commandsFiltered = commandsFiltered.filter(x => !x.systemCommand); + } + const notGroup = commandsFiltered.filter(x => x.enabled && !x.isGroupCommand); + + if (notGroup.length > 1) { + console.log('Warning, multiple commands mapped to', keyText, notGroup); + } + if (notGroup.length == 1) { const command = notGroup[0]; if (command.onClick) command.onClick(); @@ -44,6 +57,10 @@ const group = commandsFiltered.filter(x => x.enabled && x.isGroupCommand); + if (group.length > 1) { + console.log('Warning, multiple commands mapped to', keyText, group); + } + if (group.length == 1) { const command = group[0]; runGroupCommand(command.group); diff --git a/packages/web/src/commands/registerCommand.ts b/packages/web/src/commands/registerCommand.ts index c125f484..11753296 100644 --- a/packages/web/src/commands/registerCommand.ts +++ b/packages/web/src/commands/registerCommand.ts @@ -28,6 +28,7 @@ export interface GlobalCommand { toolbarOrder?: number; disableHandleKeyText?: string; isRelatedToTab?: boolean, + systemCommand?: boolean; } export default function registerCommand(command: GlobalCommand) { diff --git a/packages/web/src/commands/stdCommands.ts b/packages/web/src/commands/stdCommands.ts index 85dc10bc..297ecf15 100644 --- a/packages/web/src/commands/stdCommands.ts +++ b/packages/web/src/commands/stdCommands.ts @@ -695,6 +695,7 @@ registerCommand({ category: 'Edit', name: 'Undo', keyText: 'CtrlOrCommand+Z', + systemCommand: true, testEnabled: () => getElectron() != null, onClick: () => getElectron().send('window-action', 'undo'), }); @@ -703,6 +704,7 @@ registerCommand({ id: 'edit.redo', category: 'Edit', name: 'Redo', + systemCommand: true, testEnabled: () => getElectron() != null, onClick: () => getElectron().send('window-action', 'redo'), }); @@ -712,6 +714,7 @@ registerCommand({ category: 'Edit', name: 'Cut', keyText: 'CtrlOrCommand+X', + systemCommand: true, testEnabled: () => getElectron() != null, onClick: () => getElectron().send('window-action', 'cut'), }); @@ -721,6 +724,7 @@ registerCommand({ category: 'Edit', name: 'Copy', keyText: 'CtrlOrCommand+C', + systemCommand: true, testEnabled: () => getElectron() != null, onClick: () => getElectron().send('window-action', 'copy'), }); @@ -730,6 +734,7 @@ registerCommand({ category: 'Edit', name: 'Paste', keyText: 'CtrlOrCommand+V', + systemCommand: true, testEnabled: () => getElectron() != null, onClick: () => getElectron().send('window-action', 'paste'), });