(kb: Keybind, t?: (key: KeyLabel) => string)
| 171 | } |
| 172 | |
| 173 | function displayKeybindParts(kb: Keybind, t?: (key: KeyLabel) => string) { |
| 174 | const parts: string[] = [] |
| 175 | |
| 176 | if (kb.ctrl) parts.push(IS_MAC ? "⌃" : keyText("common.key.ctrl", t)) |
| 177 | if (kb.alt) parts.push(IS_MAC ? "⌥" : keyText("common.key.alt", t)) |
| 178 | if (kb.shift) parts.push(IS_MAC ? "⇧" : keyText("common.key.shift", t)) |
| 179 | if (kb.meta) parts.push(IS_MAC ? "⌘" : keyText("common.key.meta", t)) |
| 180 | |
| 181 | if (!kb.key) return parts |
| 182 | |
| 183 | const keys: Record<string, string> = { |
| 184 | arrowup: "↑", |
| 185 | arrowdown: "↓", |
| 186 | arrowleft: "←", |
| 187 | arrowright: "→", |
| 188 | comma: ",", |
| 189 | plus: "+", |
| 190 | } |
| 191 | const named: Record<string, KeyLabel> = { |
| 192 | backspace: "common.key.backspace", |
| 193 | delete: "common.key.delete", |
| 194 | end: "common.key.end", |
| 195 | enter: "common.key.enter", |
| 196 | esc: "common.key.esc", |
| 197 | escape: "common.key.esc", |
| 198 | home: "common.key.home", |
| 199 | insert: "common.key.insert", |
| 200 | pagedown: "common.key.pageDown", |
| 201 | pageup: "common.key.pageUp", |
| 202 | space: "common.key.space", |
| 203 | tab: "common.key.tab", |
| 204 | } |
| 205 | const key = kb.key.toLowerCase() |
| 206 | const displayKey = |
| 207 | keys[key] ?? |
| 208 | (named[key] |
| 209 | ? keyText(named[key], t) |
| 210 | : key.length === 1 |
| 211 | ? key.toUpperCase() |
| 212 | : key.charAt(0).toUpperCase() + key.slice(1)) |
| 213 | parts.push(displayKey) |
| 214 | |
| 215 | return parts |
| 216 | } |
| 217 | |
| 218 | export function formatKeybindParts(config: string, t?: (key: KeyLabel) => string): string[] { |
| 219 | if (!config || config === "none") return [] |
no test coverage detected