(keybind: Keybind)
| 235 | * Returns Mac-style symbols on macOS, or Windows-style text elsewhere. |
| 236 | */ |
| 237 | export function formatKeybind(keybind: Keybind): string { |
| 238 | const parts: string[] = []; |
| 239 | |
| 240 | if (isMac()) { |
| 241 | // Mac-style formatting with symbols (using Unicode escapes for safety) |
| 242 | // For ctrl on Mac, we actually mean Cmd in most cases since matcher treats them as equivalent |
| 243 | if (keybind.ctrl && !keybind.meta) { |
| 244 | const macCtrlBehavior = keybind.macCtrlBehavior ?? "either"; |
| 245 | if (macCtrlBehavior === "control") { |
| 246 | parts.push("\u2303"); // ⌃ Control |
| 247 | } else { |
| 248 | parts.push("\u2318"); // ⌘ Command |
| 249 | } |
| 250 | } else if (keybind.ctrl) { |
| 251 | parts.push("\u2303"); // ⌃ Control |
| 252 | } |
| 253 | if (keybind.alt) parts.push("\u2325"); // ⌥ Option |
| 254 | if (keybind.shift) parts.push("\u21E7"); // ⇧ Shift |
| 255 | if (keybind.meta) parts.push("\u2318"); // ⌘ Command |
| 256 | } else { |
| 257 | // Windows/Linux-style formatting with text |
| 258 | if (keybind.ctrl) parts.push("Ctrl"); |
| 259 | if (keybind.alt) parts.push("Alt"); |
| 260 | if (keybind.shift) parts.push("Shift"); |
| 261 | if (keybind.meta) parts.push("Meta"); |
| 262 | } |
| 263 | |
| 264 | // Add the key (handle special cases, then capitalize single letters) |
| 265 | let key: string; |
| 266 | if (keybind.key === " ") { |
| 267 | key = "Space"; |
| 268 | } else if (keybind.key.length === 1) { |
| 269 | key = keybind.key.toUpperCase(); |
| 270 | } else { |
| 271 | key = keybind.key; |
| 272 | } |
| 273 | parts.push(key); |
| 274 | |
| 275 | return isMac() ? parts.join("\u00B7") : parts.join("+"); // · on Mac, + elsewhere |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Whether a keybind is deprecated. Deprecated keybinds still match/fire, but |
no test coverage detected