MCPcopy Create free account
hub / github.com/TanStack/devtools / getHotkeyPermutations

Function getHotkeyPermutations

packages/devtools/src/utils/hotkey.ts:25–47  ·  view source on GitHub ↗
(
  hotkey: Array<KeyboardKey>,
)

Source from the content-addressed store, hash-verified

23 */
24export 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 */
49export const isHotkeyCombinationPressed = (
50 keys: Array<string>,

Callers 3

DevToolsFunction · 0.90
hotkey.test.tsFile · 0.90

Calls 2

getAllPermutationsFunction · 0.90
normalizeHotkeyFunction · 0.85

Tested by

no test coverage detected