fix keybindings

This commit is contained in:
Jan Prochazka 2022-04-18 11:08:15 +02:00
parent 0122b0accc
commit 97eff2b113
3 changed files with 24 additions and 1 deletions

View File

@ -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);

View File

@ -28,6 +28,7 @@ export interface GlobalCommand {
toolbarOrder?: number;
disableHandleKeyText?: string;
isRelatedToTab?: boolean,
systemCommand?: boolean;
}
export default function registerCommand(command: GlobalCommand) {

View File

@ -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'),
});