( hotkey: Array<KeyboardKey>, )
| 23 | * Handles CtrlOrMeta expansion and creates all possible combinations |
| 24 | */ |
| 25 | export const getHotkeyPermutations = ( |
| 26 | hotkey: Array<KeyboardKey>, |
| 27 | ): Array<Array<KeyboardKey>> => { |
| 28 | const normalizedHotkeys = normalizeHotkey(hotkey) |
| 29 | |
| 30 | return normalizedHotkeys.flatMap((normalizedHotkey) => { |
| 31 | const modifiers = normalizedHotkey.filter((key) => |
| 32 | keyboardModifiers.includes(key as any), |
| 33 | ) as Array<ModifierKey> |
| 34 | |
| 35 | const nonModifiers = normalizedHotkey.filter( |
| 36 | (key) => !keyboardModifiers.includes(key as any), |
| 37 | ) |
| 38 | |
| 39 | // handle case with no modifiers (just non-modifier keys) |
| 40 | if (modifiers.length === 0) { |
| 41 | return [nonModifiers] |
| 42 | } |
| 43 | |
| 44 | const allModifierCombinations = getAllPermutations(modifiers) |
| 45 | return allModifierCombinations.map((combo) => [...combo, ...nonModifiers]) |
| 46 | }) |
| 47 | } |
| 48 | |
| 49 | /** Checks if the currently pressed keys match any of the hotkey permutations */ |
| 50 | export const isHotkeyCombinationPressed = ( |
no test coverage detected