MCPcopy Index your code
hub / github.com/jamiebuilds/tinykeys / parseKeybinding

Function parseKeybinding

src/tinykeys.ts:171–198  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

169 * ```
170 */
171export function parseKeybinding(str: string): KeybindingPress[] {
172 return str
173 .trim()
174 .split(" ")
175 .map(press => {
176 let parts = press.split(/(?<=\w|\])\+/)
177
178 let last: string | RegExp = parts.pop() as string
179 let regex = last.match(/^\((.+)\)$/)
180 let key = regex ? new RegExp(`^(?:${regex[1]})$`, "iv") : last
181
182 let requiredModifiers: string[] = []
183 let optionalModifiers: string[] = []
184
185 for (const part of parts) {
186 let optional = part.match(/^\[(.*)\]$/)
187 let mod = optional?.[1] ?? part
188 mod = mod === "$mod" ? MOD : mod
189 if (optional) {
190 optionalModifiers.push(mod)
191 } else {
192 requiredModifiers.push(mod)
193 }
194 }
195
196 return [requiredModifiers, optionalModifiers, key]
197 })
198}
199
200/**
201 * This tells us if a single keyboard event matches a single keybinding press.

Callers 1

createKeybindingsHandlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…