MCPcopy
hub / github.com/github/hotkey / expandHotkeyToEdges

Function expandHotkeyToEdges

src/utils.ts:35–69  ·  view source on GitHub ↗
(hotkey: string)

Source from the content-addressed store, hash-verified

33}
34
35export function expandHotkeyToEdges(hotkey: string): NormalizedHotkeyString[][] {
36 // NOTE: we can't just split by comma, since comma is a valid hotkey character!
37 const output = []
38 let acc = ['']
39 let commaIsSeparator = false
40 for (let i = 0; i < hotkey.length; i++) {
41 if (commaIsSeparator && hotkey[i] === ',') {
42 output.push(acc)
43 acc = ['']
44 commaIsSeparator = false
45 continue
46 }
47
48 if (hotkey[i] === SEQUENCE_DELIMITER) {
49 // Spaces are used to separate key sequences, so a following comma is
50 // part of the sequence, not a separator.
51 acc.push('')
52 commaIsSeparator = false
53 continue
54 } else if (hotkey[i] === '+') {
55 // If the current character is a +, a following comma is part of the
56 // shortcut and not a separator.
57 commaIsSeparator = false
58 } else {
59 commaIsSeparator = true
60 }
61
62 acc[acc.length - 1] += hotkey[i]
63 }
64
65 output.push(acc)
66
67 // Remove any empty hotkeys/sequences
68 return output.map(h => h.map(k => normalizeHotkey(k)).filter(k => k !== '')).filter(h => h.length > 0)
69}

Callers 1

installFunction · 0.85

Calls 1

normalizeHotkeyFunction · 0.85

Tested by

no test coverage detected