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 * Handles CtrlOrMeta expansion and creates all possible combinations
24 */
25export 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 */
50export const isHotkeyCombinationPressed = (

Callers 3

DevToolsFunction · 0.90
hotkey.test.tsFile · 0.90

Calls 2

getAllPermutationsFunction · 0.90
normalizeHotkeyFunction · 0.85

Tested by

no test coverage detected