Spell out punctuation command shortcuts

This commit is contained in:
Jage9
2026-03-08 19:37:11 -04:00
parent f5cb5ebb78
commit c3791de3a3
2 changed files with 19 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
import { describeCharacter } from './textInput';
export type ModeInput = {
code: string;
key: string;
@@ -13,7 +15,22 @@ export type CommandDescriptor<CommandId extends string = string> = {
section: string;
};
function formatShortcutToken(token: string): string {
const trimmed = token.trim();
if (trimmed.length === 1) {
return describeCharacter(trimmed);
}
return trimmed;
}
export function formatCommandShortcut(shortcut: string): string {
return shortcut
.split('+')
.map((token) => formatShortcutToken(token))
.join('+');
}
/** Formats a palette/menu label as `Name: Key`. */
export function formatCommandMenuLabel(command: Pick<CommandDescriptor, 'label' | 'shortcut'>): string {
return `${command.label}: ${command.shortcut}`;
return `${command.label}: ${formatCommandShortcut(command.shortcut)}`;
}