(str: string)
| 169 | * ``` |
| 170 | */ |
| 171 | export 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. |
no outgoing calls
no test coverage detected
searching dependent graphs…