Open History to see the last commit
1import {
2 STATIC_KEYBINDING_COMMANDS,
3 type KeybindingCommand,
4 type KeybindingShortcut,
5 type KeybindingWhenNode,
6 type ResolvedKeybindingRule,
7 type ResolvedKeybindingsConfig,
8} from "@t3tools/contracts";
9import {
10 DEFAULT_RESOLVED_KEYBINDINGS,
11 parseKeybindingShortcut,
12 parseKeybindingWhenExpression,
13 US_SHIFTED_TO_UNSHIFTED_KEYS,
14} from "@t3tools/shared/keybindings";
15import { msg } from "gt-react";
16
17import { m, type MessageResolver } from "../../i18n/messages";
18import { shortcutConflictKey, shortcutKeyFromEvent } from "../../keybindings";
19import { isMacPlatform } from "../../lib/utils";
20import { METRIC_OPTIONS, WINDOW_OPTIONS } from "../usage/usageShortcuts";
21
22// Rank every usage command; mixing rank and alphabetical comparisons makes order input-dependent.
23const usageCommandOrder = new Map<KeybindingCommand, number>(
24 [
25 "usage.open" as const,
26 ...[...METRIC_OPTIONS, ...WINDOW_OPTIONS].map((option) => option.command),
27 ].map((command, index) => [command, index]),
28);
29
30const firstUsageCommand = METRIC_OPTIONS[0].command;
31
32function compareCommands(
33 left: KeybindingCommand,
34 right: KeybindingCommand,
35 key: (command: KeybindingCommand) => string,
36): number {
37 const leftRank = usageCommandOrder.get(left);
38 const rightRank = usageCommandOrder.get(right);
39 if (leftRank !== undefined && rightRank !== undefined) return leftRank - rightRank;
40 return key(leftRank === undefined ? left : firstUsageCommand).localeCompare(
41 key(rightRank === undefined ? right : firstUsageCommand),
42 );
43}
44
45export type KeybindingSource = "Default" | "Custom" | "Project";
46
47export interface KeybindingRow {
48 readonly id: string;
49 readonly command: KeybindingCommand;
50 readonly key: string;
51 readonly when: string;
52 readonly source: KeybindingSource;
53 readonly isUnassigned: boolean;
54 readonly defaultKey: string | null;
55 readonly defaultWhen: string;
56 readonly binding: ResolvedKeybindingRule;
57 readonly conflicts: ReadonlyArray<string>;
58}
59
60export type WhenVariableOption = string;
61export type KeybindingCommandOption = KeybindingCommand;
62
63const CORE_WHEN_VARIABLES = [
64 "terminalFocus",
65 "terminalOpen",
66 "previewOpen",
67 "isWeb",
68 "isDesktop",
69 "true",
70 "false",
71] as const;
72
73const DEFAULT_WHEN_VARIABLES = new Set<string>(CORE_WHEN_VARIABLES);
74for (const binding of DEFAULT_RESOLVED_KEYBINDINGS) {
75 collectWhenIdentifiersFromNode(binding.whenAst, DEFAULT_WHEN_VARIABLES);
76}
77
78export const DEFAULT_WHEN_VARIABLE =
79 [...DEFAULT_WHEN_VARIABLES].find(
80 (identifier) => identifier !== "true" && identifier !== "false",
81 ) ?? "terminalFocus";
82const KNOWN_WHEN_VARIABLES = new Set(DEFAULT_WHEN_VARIABLES);
83
84export function shortcutToKeybindingInput(shortcut: KeybindingShortcut): string {
85 const parts: string[] = [];
86 if (shortcut.modKey) parts.push("mod");
87 if (shortcut.metaKey) parts.push("meta");
88 if (shortcut.ctrlKey) parts.push("ctrl");
89 if (shortcut.altKey) parts.push("alt");
90 if (shortcut.shiftKey) parts.push("shift");
91 parts.push(shortcut.key === " " ? "space" : shortcut.key === "escape" ? "esc" : shortcut.key);
92 return parts.join("+");
93}
94
95export function whenAstToExpression(node: KeybindingWhenNode | undefined): string {
96 if (!node) return "";
97 switch (node.type) {
98 case "identifier":
99 return node.name;
100 case "not":
101 return `!${wrapWhenExpression(node.node)}`;
102 case "and":
103 return `${wrapWhenExpression(node.left)} && ${wrapWhenExpression(node.right)}`;
104 case "or":
105 return `${wrapWhenExpression(node.left)} || ${wrapWhenExpression(node.right)}`;
106 }
107}
108
109export function whenNodeRemoveLabel(
110 node: KeybindingWhenNode,
111 depth: number,
112 resolve: MessageResolver = m,
113): string {
114 if (depth === 0) return resolve(msg("Clear all conditions"));
115 if (node.type === "identifier" || (node.type === "not" && node.node.type === "identifier")) {
116 return resolve(msg("Remove condition"));
117 }
118 return resolve(msg("Remove group and its conditions"));
119}
120
121function wrapWhenExpression(node: KeybindingWhenNode): string {
122 if (node.type === "identifier" || node.type === "not") return whenAstToExpression(node);
123 return `(${whenAstToExpression(node)})`;
124}
125
126export function parseWhenExpressionDraft(
127 expression: string,
128 resolve: MessageResolver = m,
129): { ok: true; value: KeybindingWhenNode | undefined } | { ok: false; message: string } {
130 const trimmed = expression.trim();
131 if (trimmed.length === 0) return { ok: true, value: undefined };
132
133 const ast = parseKeybindingWhenExpression(trimmed);
134 if (!ast) {
135 return {
136 ok: false,
137 message: resolve(msg("Use variables with !, &&, ||, and parentheses.")),
138 };
139 }
140
141 return { ok: true, value: ast };
142}
143
144function sourceForBinding(binding: ResolvedKeybindingRule): KeybindingSource {
145 if (String(binding.command).startsWith("script.")) {
146 const source: KeybindingSource = "Project";
147 return source;
148 }
149
150 const bindingKey = shortcutToKeybindingInput(binding.shortcut);
151 const bindingWhen = whenAstToExpression(binding.whenAst);
152 const isDefault = DEFAULT_RESOLVED_KEYBINDINGS.some(
153 (entry) =>
154 entry.command === binding.command &&
155 shortcutToKeybindingInput(entry.shortcut) === bindingKey &&
156 whenAstToExpression(entry.whenAst) === bindingWhen,
157 );
158
159 const source: KeybindingSource = isDefault ? "Default" : "Custom";
160 return source;
161}
162
163function defaultBindingForBinding(
164 binding: ResolvedKeybindingRule,
165): ResolvedKeybindingRule | undefined {
166 const bindingKey = shortcutToKeybindingInput(binding.shortcut);
167 const bindingWhen = whenAstToExpression(binding.whenAst);
168
169 return (
170 DEFAULT_RESOLVED_KEYBINDINGS.find(
171 (entry) =>
172 entry.command === binding.command &&
173 shortcutToKeybindingInput(entry.shortcut) === bindingKey &&
174 whenAstToExpression(entry.whenAst) === bindingWhen,
175 ) ??
176 (bindingWhen === "false"
177 ? DEFAULT_RESOLVED_KEYBINDINGS.find(
178 (entry) =>
179 entry.command === binding.command &&
180 shortcutToKeybindingInput(entry.shortcut) === bindingKey,
181 )
182 : undefined) ??
183 DEFAULT_RESOLVED_KEYBINDINGS.find(
184 (entry) =>
185 entry.command === binding.command && whenAstToExpression(entry.whenAst) === bindingWhen,
186 ) ??
187 DEFAULT_RESOLVED_KEYBINDINGS.find((entry) => entry.command === binding.command)
188 );
189}
190
191function keybindingRowId(command: KeybindingCommand, key: string, when: string): string {
192 return `${command}\u0000${key}\u0000${when}`;
193}
194
195function conflictsWithWhen(leftWhen: string, rightWhen: string): boolean {
196 if (leftWhen === "false" || rightWhen === "false") return false;
197 return leftWhen.length === 0 || rightWhen.length === 0 || leftWhen === rightWhen;
198}
199
200export function keybindingConflictLabels(
201 rows: ReadonlyArray<KeybindingRow>,
202 input: { readonly rowId: string; readonly key: string; readonly when: string },
203 platform = navigator.platform,
204 resolve: MessageResolver = m,
205): ReadonlyArray<string> {
206 if (input.key.trim().length === 0) return [];
207 const shortcut = parseKeybindingShortcut(input.key);
208 if (!shortcut) return [];
209 // Compare resolved chords so mod+k and ctrl+k collide where mod is Ctrl.
210 const conflictKey = shortcutConflictKey(shortcut, platform);
211 const conflicts: Array<string> = [];
212 for (const candidate of rows) {
213 if (
214 candidate.id !== input.rowId &&
215 shortcutConflictKey(candidate.binding.shortcut, platform) === conflictKey &&
216 conflictsWithWhen(candidate.when, input.when)
217 ) {
218 conflicts.push(commandLabel(candidate.command, resolve));
219 }
220 }
221 return [...new Set(conflicts)].toSorted();
222}
223
224export interface KeybindingGroup {
225 readonly id: string;
226 readonly title: string;
227 readonly rows: ReadonlyArray<KeybindingRow>;
228}
229
230const KEYBINDING_GROUPS = [
231 {
232 id: "navigation",
233 title: msg("Navigation"),
234 prefixes: ["sidebar", "rightPanel", "commandPalette", "filePicker", "projectSearch", "editor"],
235 },
236 { id: "threads", title: msg("Threads"), prefixes: ["thread", "chat", "pullRequest"] },
237 { id: "composer", title: msg("Composer"), prefixes: ["composer", "modelPicker"] },
238 { id: "terminal", title: msg("Terminal"), prefixes: ["terminal"] },
239 { id: "preview", title: msg("Preview & diff"), prefixes: ["preview", "diff"] },
240 {
241 id: "appearance",
242 title: msg("Appearance"),
243 prefixes: ["theme", "appearance", "themeEditor"],
244 },
245 { id: "scripts", title: msg("Project scripts"), prefixes: ["script"] },
246] as const;
247const OTHER_KEYBINDING_GROUP = {
248 id: "other",
249 title: msg("Other", { $context: "keybinding group" }),
250} as const;
251
252function keybindingGroupFor(command: KeybindingCommand): { id: string; title: string } {
253 const prefix = String(command).split(".")[0] ?? "";
254 return (
255 KEYBINDING_GROUPS.find((group) => (group.prefixes as ReadonlyArray<string>).includes(prefix)) ??
256 OTHER_KEYBINDING_GROUP
257 );
258}
259
260export function groupKeybindingRows(
261 rows: ReadonlyArray<KeybindingRow>,
262): ReadonlyArray<KeybindingGroup> {
263 const rowsByGroup = new Map<string, Array<KeybindingRow>>();
264 for (const row of rows) {
265 const group = keybindingGroupFor(row.command);
266 const bucket = rowsByGroup.get(group.id);
267 if (bucket) bucket.push(row);
268 else rowsByGroup.set(group.id, [row]);
269 }
270 return [...KEYBINDING_GROUPS, OTHER_KEYBINDING_GROUP].flatMap((group) => {
271 const groupRows = rowsByGroup.get(group.id);
272 return groupRows ? [{ id: group.id, title: group.title, rows: groupRows }] : [];
273 });
274}
275
276export function buildKeybindingRows(
277 keybindings: ResolvedKeybindingsConfig,
278 platform = navigator.platform,
279 resolve: MessageResolver = m,
280): ReadonlyArray<KeybindingRow> {
281 const rowsById = new Map<string, KeybindingRow>();
282 for (const binding of keybindings) {
283 const defaultBinding = defaultBindingForBinding(binding);
284 const key = shortcutToKeybindingInput(binding.shortcut);
285 const when = whenAstToExpression(binding.whenAst);
286 const id = keybindingRowId(binding.command, key, when);
287 rowsById.set(id, {
288 id,
289 command: binding.command,
290 key,
291 when,
292 source: sourceForBinding(binding),
293 isUnassigned:
294 when === "false" &&
295 defaultBinding !== undefined &&
296 key === shortcutToKeybindingInput(defaultBinding.shortcut),
297 defaultKey: defaultBinding ? shortcutToKeybindingInput(defaultBinding.shortcut) : null,
298 defaultWhen: whenAstToExpression(defaultBinding?.whenAst),
299 binding,
300 conflicts: [],
301 });
302 }
303 const rows = [...rowsById.values()];
304
305 const rowsWithConflicts = rows.map((row) => {
306 const conflicts = keybindingConflictLabels(
307 rows,
308 {
309 rowId: row.id,
310 key: row.key,
311 when: row.when,
312 },
313 platform,
314 resolve,
315 );
316 return conflicts.length > 0
317 ? Object.assign({}, row, { conflicts: [...new Set(conflicts)].toSorted() })
318 : row;
319 });
320
321 rowsWithConflicts.sort((left, right) => {
322 const commandCompare = compareCommands(left.command, right.command, (command) => command);
323 if (commandCompare !== 0) return commandCompare;
324 return left.key.localeCompare(right.key);
325 });
326
327 return rowsWithConflicts;
328}
329
330export function filterKeybindingRows(
331 rows: ReadonlyArray<KeybindingRow>,
332 query: string,
333 resolve: MessageResolver = m,
334): ReadonlyArray<KeybindingRow> {
335 const normalizedQuery = query.trim().toLowerCase();
336 if (normalizedQuery.length === 0) return rows;
337 return rows.filter((row) => {
338 return (
339 row.command.toLowerCase().includes(normalizedQuery) ||
340 commandLabel(row.command, resolve).toLowerCase().includes(normalizedQuery) ||
341 row.key.toLowerCase().includes(normalizedQuery) ||
342 row.when.toLowerCase().includes(normalizedQuery) ||
343 row.source.toLowerCase().includes(normalizedQuery)
344 );
345 });
346}
347
348function collectWhenIdentifiersFromNode(
349 node: KeybindingWhenNode | undefined,
350 identifiers: Set<string>,
351): void {
352 if (!node) return;
353 switch (node.type) {
354 case "identifier":
355 identifiers.add(node.name);
356 return;
357 case "not":
358 collectWhenIdentifiersFromNode(node.node, identifiers);
359 return;
360 case "and":
361 case "or":
362 collectWhenIdentifiersFromNode(node.left, identifiers);
363 collectWhenIdentifiersFromNode(node.right, identifiers);
364 return;
365 }
366}
367
368export function isKnownWhenVariable(identifier: string): boolean {
369 return KNOWN_WHEN_VARIABLES.has(identifier);
370}
371
372export function unknownWhenVariables(node: KeybindingWhenNode | undefined): ReadonlyArray<string> {
373 const identifiers = new Set<string>();
374 collectWhenIdentifiersFromNode(node, identifiers);
375 return [...identifiers].filter((identifier) => !isKnownWhenVariable(identifier)).toSorted();
376}
377
378export function buildWhenVariableOptions(): ReadonlyArray<WhenVariableOption> {
379 return [...KNOWN_WHEN_VARIABLES].toSorted((left, right) => {
380 const leftCoreIndex = CORE_WHEN_VARIABLES.indexOf(left as (typeof CORE_WHEN_VARIABLES)[number]);
381 const rightCoreIndex = CORE_WHEN_VARIABLES.indexOf(
382 right as (typeof CORE_WHEN_VARIABLES)[number],
383 );
384 if (leftCoreIndex !== -1 || rightCoreIndex !== -1) {
385 return (
386 (leftCoreIndex === -1 ? Number.MAX_SAFE_INTEGER : leftCoreIndex) -
387 (rightCoreIndex === -1 ? Number.MAX_SAFE_INTEGER : rightCoreIndex)
388 );
389 }
390 return left.localeCompare(right);
391 });
392}
393
394export function buildKeybindingCommandOptions(
395 keybindings: ResolvedKeybindingsConfig,
396 resolve: MessageResolver = m,
397): ReadonlyArray<KeybindingCommandOption> {
398 const commands = new Set<KeybindingCommand>(STATIC_KEYBINDING_COMMANDS);
399 for (const binding of keybindings) {
400 commands.add(binding.command);
401 }
402 return [...commands].toSorted((left, right) =>
403 compareCommands(left, right, (command) => commandLabel(command, resolve)),
404 );
405}
406
407const COMMAND_LABELS: Partial<Record<KeybindingCommand, string>> = {
408 "workspace.focusNext": msg("Focus Next Workspace Area"),
409 "workspace.focusPrevious": msg("Focus Previous Workspace Area"),
410 "composer.sendAlternate": msg("Composer: Opposite Queue or Steer Action"),
411 "composer.sendBackground": msg("Composer: Start in Background"),
412 "composer.sendAndNewThread": msg("Composer: Send and Start New Thread"),
413 "composer.dictation": msg("Composer: Start or Finish Dictation"),
414 "thread.steerQueuedMessage": msg("Queue: Send First Queued Message"),
415 "thread.editQueuedMessage": msg("Queue: Edit Last Queued Message"),
416 "thread.copyReference": msg("Pull Request: Copy Link or Thread"),
417 "sidebar.toggle": msg("Sidebar: Toggle"),
418 "navigation.back": msg("Navigation: Back"),
419 "navigation.forward": msg("Navigation: Forward"),
420 "terminal.toggle": msg("Terminal: Toggle"),
421 "terminal.split": msg("Terminal: Split"),
422 "terminal.splitVertical": msg("Terminal: Split Vertical"),
423 "terminal.new": msg("Terminal: New"),
424 "terminal.close": msg("Terminal: Close"),
425 "rightPanel.toggle": msg("Right Panel: Toggle"),
426 "rightPanel.new": msg("Right Panel: New"),
427 "threadPanel.toggle": msg("Thread Panel: Toggle"),
428 "rightPanel.toggleMaximized": msg("Right Panel: Toggle Maximized"),
429 "rightPanel.close": msg("Right Panel: Close"),
430 "pullRequest.copyNumber": msg("Pull Request: Copy Number"),
431 "diff.toggle": msg("Diff: Toggle"),
432 "preview.toggle": msg("Preview: Toggle"),
433 "preview.refresh": msg("Preview: Refresh"),
434 "preview.zoomIn": msg("Preview: Zoom In"),
435 "preview.zoomOut": msg("Preview: Zoom Out"),
436 "preview.resetZoom": msg("Preview: Reset Zoom"),
437 "commandPalette.toggle": msg("Command Palette: Toggle"),
438 "filePicker.toggle": msg("File Picker: Toggle"),
439 "projectSearch.toggle": msg("Project Search: Toggle"),
440 "usage.open": msg("Usage: Open"),
441 "theme.select": msg("Theme: Select"),
442 "appearance.cycle": msg("Appearance: Cycle"),
443 "themeEditor.toggle": msg("Theme Editor: Toggle"),
444 "composer.stash": msg("Composer: Stash"),
445 "composer.host": msg("Composer: Host"),
446 "composer.cycleHost": msg("Composer: Cycle Host"),
447 "composer.effort": msg("Composer: Effort"),
448 "composer.increaseEffort": msg("Composer: Increase Effort"),
449 "composer.decreaseEffort": msg("Composer: Decrease Effort"),
450 "composer.mode": msg("Composer: Mode"),
451 "composer.workspace": msg("Composer: Workspace"),
452 "composer.previousWorktree": msg("Composer: Previous Worktree"),
453 "composer.branch": msg("Composer: Branch"),
454 "chat.new": msg("Chat: New"),
455 "chat.newLocal": msg("Chat: New Local"),
456 "chat.newWithoutProject": msg("Chat: New Without Project"),
457 "chat.find": msg("Chat: Find"),
458 "editor.openFavorite": msg("Editor: Open Favorite"),
459 "modelPicker.toggle": msg("Model Picker: Toggle"),
460 "modelPicker.previousProvider": msg("Model Picker: Previous Provider"),
461 "modelPicker.nextProvider": msg("Model Picker: Next Provider"),
462 "thread.stop": msg("Thread: Stop"),
463 "thread.previous": msg("Thread: Previous"),
464 "thread.next": msg("Thread: Next"),
465 "thread.settle": msg("Thread: Settle"),
466 "thread.pin": msg("Thread: Pin"),
467 "thread.regenerateTitle": msg("Thread: Regenerate Title"),
468 "thread.undo": msg("Thread: Undo"),
469};
470
471// Whole labels: search titles keep the encoded message, which cannot nest another one.
472const USAGE_COMMAND_LABELS: Record<
473 (typeof METRIC_OPTIONS)[number]["command"] | (typeof WINDOW_OPTIONS)[number]["command"],
474 string
475> = {
476 "usage.cost": msg("Usage: Cost"),
477 "usage.tokens": msg("Usage: Tokens"),
478 "usage.limits": msg("Usage: Limits"),
479 "usage.period.day": msg("Usage: Period: Past 24h"),
480 "usage.period.week": msg("Usage: Period: 7 days"),
481 "usage.period.month": msg("Usage: Period: 30 days"),
482 "usage.period.quarter": msg("Usage: Period: 90 days"),
483};
484
485const LATE_COMMAND_LABELS: Partial<Record<KeybindingCommand, string>> = {
486 "view.reopenClosed": msg("Reopen Closed Tab"),
487 "preview.focusUrl": msg("Preview: Focus URL"),
488 "preview.find": msg("Preview: Find on Page"),
489};
490
491export function commandLabel(command: KeybindingCommand, resolve: MessageResolver = m): string {
492 const label = COMMAND_LABELS[command];
493 if (label) return resolve(label);
494 const usageLabel = USAGE_COMMAND_LABELS[command as keyof typeof USAGE_COMMAND_LABELS];
495 if (usageLabel) return resolve(usageLabel);
496 const lateLabel = LATE_COMMAND_LABELS[command];
497 if (lateLabel) return resolve(lateLabel);
498 const raw = String(command);
499 if (raw.startsWith("thread.jump.")) {
500 return resolve(msg("Thread: Jump: {n}", { n: raw.slice("thread.jump.".length) }));
501 }
502 if (raw.startsWith("modelPicker.jump.")) {
503 return resolve(msg("Model Picker: Jump: {n}", { n: raw.slice("modelPicker.jump.".length) }));
504 }
505 if (raw.startsWith("script.") && raw.endsWith(".run")) {
506 return resolve(
507 msg("Run Script: {name}", {
508 name: titleCaseCommandSegment(raw.slice("script.".length, -".run".length)),
509 }),
510 );
511 }
512 return raw.split(".").map(titleCaseCommandSegment).join(": ");
513}
514
515function titleCaseCommandSegment(segment: string): string {
516 const words: Array<string> = [];
517 for (const part of segment.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[-_\s]+/)) {
518 if (part.length > 0) {
519 words.push(part.slice(0, 1).toUpperCase() + part.slice(1));
520 }
521 }
522 return words.join(" ");
523}
524
525function recordedLayoutShortcutKey(
526 event: Pick<KeyboardEvent, "key" | "code" | "shiftKey" | "altKey">,
527): string {
528 const physicalKey = shortcutKeyFromEvent(event);
529 const layoutKey = event.key.toLowerCase();
530 if (event.altKey || layoutKey.length !== 1) return physicalKey;
531 // Normalize only US shifted glyphs at their US position. Other layouts can
532 // produce the same glyph without Shift or at a different position.
533 const unshiftedKey = event.shiftKey ? US_SHIFTED_TO_UNSHIFTED_KEYS.get(layoutKey) : undefined;
534 return unshiftedKey === physicalKey ? physicalKey : layoutKey;
535}
536
537function normalizeShortcutKeyToken(key: string): string | null {
538 const normalized = key.toLowerCase();
539 if (
540 normalized === "meta" ||
541 normalized === "control" ||
542 normalized === "ctrl" ||
543 normalized === "shift" ||
544 normalized === "alt" ||
545 normalized === "option"
546 ) {
547 return null;
548 }
549 if (normalized === " ") return "space";
550 if (normalized === "escape") return "esc";
551 if (normalized === "arrowup") return "arrowup";
552 if (normalized === "arrowdown") return "arrowdown";
553 if (normalized === "arrowleft") return "arrowleft";
554 if (normalized === "arrowright") return "arrowright";
555 if (normalized.length === 1) return normalized;
556 if (/^f\d{1,2}$/.test(normalized)) return normalized;
557 if (normalized === "enter" || normalized === "tab" || normalized === "backspace") {
558 return normalized;
559 }
560 if (normalized === "delete" || normalized === "home" || normalized === "end") {
561 return normalized;
562 }
563 if (normalized === "pageup" || normalized === "pagedown") return normalized;
564 return null;
565}
566
567export function keybindingFromKeyboardEvent(
568 event: Pick<KeyboardEvent, "key" | "code" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey">,
569 platform: string,
570 options?: {
571 readonly layoutCharacter?: boolean;
572 },
573): string | null {
574 const keyToken = normalizeShortcutKeyToken(
575 options?.layoutCharacter ? recordedLayoutShortcutKey(event) : shortcutKeyFromEvent(event),
576 );
577 if (!keyToken) return null;
578
579 const parts: string[] = [];
580 if (isMacPlatform(platform)) {
581 if (event.metaKey) parts.push("mod");
582 if (event.ctrlKey) parts.push("ctrl");
583 } else {
584 if (event.ctrlKey) parts.push("mod");
585 if (event.metaKey) parts.push("meta");
586 }
587 if (event.altKey) parts.push("alt");
588 if (event.shiftKey) parts.push("shift");
589 parts.push(keyToken);
590 return parts.join("+");
591}