Spell out punctuation command shortcuts
This commit is contained in:
@@ -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)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user