(config: string)
| 108 | } |
| 109 | |
| 110 | export function parseKeybind(config: string): Keybind[] { |
| 111 | if (!config || config === "none") return [] |
| 112 | |
| 113 | return config.split(",").map((combo) => { |
| 114 | const parts = combo.trim().toLowerCase().split("+") |
| 115 | const keybind: Keybind = { |
| 116 | key: "", |
| 117 | ctrl: false, |
| 118 | meta: false, |
| 119 | shift: false, |
| 120 | alt: false, |
| 121 | } |
| 122 | |
| 123 | for (const part of parts) { |
| 124 | switch (part) { |
| 125 | case "ctrl": |
| 126 | case "control": |
| 127 | keybind.ctrl = true |
| 128 | break |
| 129 | case "meta": |
| 130 | case "cmd": |
| 131 | case "command": |
| 132 | keybind.meta = true |
| 133 | break |
| 134 | case "mod": |
| 135 | if (IS_MAC) keybind.meta = true |
| 136 | else keybind.ctrl = true |
| 137 | break |
| 138 | case "alt": |
| 139 | case "option": |
| 140 | keybind.alt = true |
| 141 | break |
| 142 | case "shift": |
| 143 | keybind.shift = true |
| 144 | break |
| 145 | default: |
| 146 | keybind.key = part |
| 147 | break |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return keybind |
| 152 | }) |
| 153 | } |
| 154 | |
| 155 | export function matchKeybind(keybinds: Keybind[], event: KeyboardEvent): boolean { |
| 156 | const eventKey = normalizeKey(event.key) |
no outgoing calls
no test coverage detected