From 9f2ab0972929b6fc9e0da4ef538563a850bf2c90 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 11 Jul 2022 14:49:24 -0700 Subject: [PATCH] Special handle the CMD+K keys so they dont interfere with regular keyboard commands --- .../web/lib/keyboardShortcuts/useKeyboardShortcuts.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/web/lib/keyboardShortcuts/useKeyboardShortcuts.ts b/packages/web/lib/keyboardShortcuts/useKeyboardShortcuts.ts index da7beeac4..1834b27c3 100644 --- a/packages/web/lib/keyboardShortcuts/useKeyboardShortcuts.ts +++ b/packages/web/lib/keyboardShortcuts/useKeyboardShortcuts.ts @@ -61,6 +61,10 @@ export const useKeyboardShortcuts = (commands: KeyboardCommand[]): void => { const [keys, setKeys] = useReducer(keysReducer, initalKeyMapping) + const metaPressed = useCallback(() => { + return keys['meta'] === true + }, [keys]) + const applyCommands = useCallback( (updatedKeys: KeyPressed, disabled?: boolean) => { let commandApplied = false @@ -69,6 +73,7 @@ export const useKeyboardShortcuts = (commands: KeyboardCommand[]): void => { return } const tempState = { ...updatedKeys } + const arePressed = command.shortcutKeys.every((key) => { const aliases = key.split('|') for (const k of aliases) { @@ -107,6 +112,10 @@ export const useKeyboardShortcuts = (commands: KeyboardCommand[]): void => { if (keys[key] === undefined) return if (keys[key] === false) { + if (key === 'k' && metaPressed()) { + // not setting the K value because meta is already pressed + return + } setKeys({ type: ActionType.SET_KEY_DOWN, key }) } const commandApplied = applyCommands(