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