Files
plainleaf/plug-api/lib/shortcut.ts
T
Zef Hemel b207e8a06e Client: extract prettifyShortcut into shared lib
Move isMacLike and prettifyShortcut out of command_palette into plug-api/lib/shortcut so the configuration manager's shortcuts UI can render identical key notation.
2026-04-21 16:54:24 +02:00

17 lines
497 B
TypeScript

export const isMacLike = typeof navigator !== "undefined" &&
/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
export function prettifyShortcut(shortcut: string): string {
if (!isMacLike) return shortcut;
const pretty = shortcut
.replace(/Mod-/g, "⌘")
.replace(/Cmd-/g, "⌘")
.replace(/Ctrl-/g, "⌃")
.replace(/Alt-/g, "⌥")
.replace(/Shift-/g, "⇧");
return pretty.replace(
/([⌘⌃⌥⇧])([a-z])$/,
(_, mod, key) => mod + key.toUpperCase(),
);
}