Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

keybindings.test.ts

1,379 lines41.5 KB

1import { assert, describe, it } from "vite-plus/test";
2import {
3 compileResolvedKeybindingsConfig,
4 DEFAULT_RESOLVED_KEYBINDINGS,
5 mergeWithDefaultKeybindings,
6} from "@t3tools/shared/keybindings";
7​
8import {
9 type KeybindingCommand,
10 type KeybindingShortcut,
11 type KeybindingWhenNode,
12 type ResolvedKeybindingsConfig,
13} from "@t3tools/contracts";
14import {
15 formatShortcutLabel,
16 isDiffToggleShortcut,
17 isRichTextBoldShortcut,
18 modelPickerJumpCommandForIndex,
19 modelPickerJumpIndexFromCommand,
20 isOpenFavoriteEditorShortcut,
21 isTerminalClearShortcut,
22 isTerminalCloseShortcut,
23 isTerminalNewShortcut,
24 isTerminalSplitShortcut,
25 isTerminalSplitVerticalShortcut,
26 isTerminalToggleShortcut,
27 resolveShortcutCommand,
28 shouldShowThreadJumpHintsForModifiers,
29 shortcutLabelForCommand,
30 terminalDeleteShortcutData,
31 terminalNavigationShortcutData,
32 threadJumpCommandForIndex,
33 threadJumpIndexFromCommand,
34 threadTraversalDirectionFromCommand,
35 type ShortcutEventLike,
36} from "./keybindings";
37​
38function event(overrides: Partial<ShortcutEventLike> = {}): ShortcutEventLike {
39 return {
40 key: "j",
41 metaKey: false,
42 ctrlKey: false,
43 shiftKey: false,
44 altKey: false,
45 ...overrides,
46 };
48​
49function modShortcut(
50 key: string,
51 overrides: Partial<Omit<KeybindingShortcut, "key">> = {},
52): KeybindingShortcut {
53 return {
54 key,
55 metaKey: false,
56 ctrlKey: false,
57 shiftKey: false,
58 altKey: false,
59 modKey: true,
60 ...overrides,
61 };
63​
64function whenIdentifier(name: string): KeybindingWhenNode {
65 return { type: "identifier", name };
67​
68function whenNot(node: KeybindingWhenNode): KeybindingWhenNode {
69 return { type: "not", node };
71​
72function whenAnd(left: KeybindingWhenNode, right: KeybindingWhenNode): KeybindingWhenNode {
73 return { type: "and", left, right };
75​
76interface TestBinding {
77 shortcut: KeybindingShortcut;
78 command: KeybindingCommand;
79 whenAst?: KeybindingWhenNode;
81​
82function compile(bindings: TestBinding[]): ResolvedKeybindingsConfig {
83 return bindings.map((binding) => ({
84 command: binding.command,
85 shortcut: binding.shortcut,
86 ...(binding.whenAst ? { whenAst: binding.whenAst } : {}),
87 }));
89​
90const DEFAULT_BINDINGS = compile([
91 { shortcut: modShortcut("b"), command: "sidebar.toggle" },
92 { shortcut: modShortcut("j"), command: "terminal.toggle" },
93 { shortcut: modShortcut("b", { altKey: true }), command: "rightPanel.toggle" },
94 {
95 shortcut: modShortcut("d"),
96 command: "terminal.split",
97 whenAst: whenIdentifier("terminalFocus"),
98 },
99 {
100 shortcut: modShortcut("d", { shiftKey: true }),
101 command: "terminal.splitVertical",
102 whenAst: whenIdentifier("terminalFocus"),
103 },
104 {
105 shortcut: modShortcut("n"),
106 command: "terminal.new",
107 whenAst: whenIdentifier("terminalFocus"),
108 },
109 {
110 shortcut: modShortcut("w"),
111 command: "terminal.close",
112 whenAst: whenIdentifier("terminalFocus"),
113 },
114 {
115 shortcut: modShortcut("w"),
116 command: "rightPanel.close",
117 whenAst: whenNot(whenIdentifier("terminalFocus")),
118 },
119 {
120 shortcut: modShortcut("d"),
121 command: "diff.toggle",
122 whenAst: whenNot(whenIdentifier("terminalFocus")),
123 },
124 {
125 shortcut: modShortcut("k"),
126 command: "commandPalette.toggle",
127 whenAst: whenNot(whenIdentifier("terminalFocus")),
128 },
129 {
130 shortcut: modShortcut("p"),
131 command: "filePicker.toggle",
132 whenAst: whenNot(whenIdentifier("terminalFocus")),
133 },
134 {
135 shortcut: modShortcut("f", { shiftKey: true }),
136 command: "projectSearch.toggle",
137 whenAst: whenNot(whenIdentifier("terminalFocus")),
138 },
139 {
140 shortcut: modShortcut("t", { altKey: true, shiftKey: true }),
141 command: "themeEditor.toggle",
142 },
143 {
144 shortcut: modShortcut("m", { shiftKey: true }),
145 command: "modelPicker.toggle",
146 whenAst: whenNot(whenIdentifier("terminalFocus")),
147 },
148 { shortcut: modShortcut("o", { shiftKey: true }), command: "chat.new" },
149 { shortcut: modShortcut("n", { shiftKey: true }), command: "chat.newLocal" },
150 { shortcut: modShortcut("o"), command: "editor.openFavorite" },
151 { shortcut: modShortcut("[", { shiftKey: true }), command: "thread.previous" },
152 { shortcut: modShortcut("]", { shiftKey: true }), command: "thread.next" },
153 {
154 shortcut: modShortcut("c", { shiftKey: true }),
155 command: "thread.copyReference",
156 whenAst: whenNot(whenIdentifier("terminalFocus")),
157 },
158 {
159 shortcut: modShortcut("s", { shiftKey: true }),
160 command: "thread.settle",
161 whenAst: whenNot(whenIdentifier("terminalFocus")),
162 },
163 { shortcut: modShortcut("1"), command: "thread.jump.1" },
164 { shortcut: modShortcut("2"), command: "thread.jump.2" },
165 { shortcut: modShortcut("3"), command: "thread.jump.3" },
166 {
167 shortcut: modShortcut("1"),
168 command: "modelPicker.jump.1",
169 whenAst: whenIdentifier("modelPickerOpen"),
170 },
171 {
172 shortcut: modShortcut("2"),
173 command: "modelPicker.jump.2",
174 whenAst: whenIdentifier("modelPickerOpen"),
175 },
176 {
177 shortcut: modShortcut("3"),
178 command: "modelPicker.jump.3",
179 whenAst: whenIdentifier("modelPickerOpen"),
180 },
181]);
182​
183describe("isTerminalToggleShortcut", () => {
184 it("matches Cmd+J on macOS", () => {
185 assert.isTrue(
186 isTerminalToggleShortcut(event({ metaKey: true }), DEFAULT_BINDINGS, {
187 platform: "MacIntel",
188 }),
189 );
190 });
191​
192 it("matches Ctrl+J on non-macOS", () => {
193 assert.isTrue(
194 isTerminalToggleShortcut(event({ ctrlKey: true }), DEFAULT_BINDINGS, { platform: "Win32" }),
195 );
196 });
197​
198 it("matches Ctrl+J on non-macOS while terminalFocus is true", () => {
199 assert.isTrue(
200 isTerminalToggleShortcut(event({ ctrlKey: true }), DEFAULT_BINDINGS, {
201 platform: "Win32",
202 context: { terminalFocus: true },
203 }),
204 );
205 });
206});
207​
208describe("settle thread shortcut", () => {
209 it("resolves outside the terminal", () => {
210 assert.equal(
211 resolveShortcutCommand(event({ key: "s", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
212 platform: "MacIntel",
213 context: { terminalFocus: false },
214 }),
215 "thread.settle",
216 );
217 });
218​
219 it("does not intercept the terminal", () => {
220 assert.isNull(
221 resolveShortcutCommand(event({ key: "s", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
222 platform: "Win32",
223 context: { terminalFocus: true },
224 }),
225 );
226 });
227});
228​
229describe("thread undo shortcut", () => {
230 it("resolves mod+z with nothing editable focused", () => {
231 assert.equal(
232 resolveShortcutCommand(event({ key: "z", metaKey: true }), DEFAULT_RESOLVED_KEYBINDINGS, {
233 platform: "MacIntel",
234 context: { terminalFocus: false, editableFocus: false },
235 }),
236 "thread.undo",
237 );
238 });
239​
240 it("leaves native undo alone inside text fields and terminals", () => {
241 assert.isNull(
242 resolveShortcutCommand(event({ key: "z", ctrlKey: true }), DEFAULT_RESOLVED_KEYBINDINGS, {
243 platform: "Win32",
244 context: { editableFocus: true },
245 }),
246 );
247 assert.isNull(
248 resolveShortcutCommand(event({ key: "z", ctrlKey: true }), DEFAULT_RESOLVED_KEYBINDINGS, {
249 platform: "Win32",
250 context: { terminalFocus: true },
251 }),
252 );
253 });
254});
255​
256describe("copy thread reference shortcut", () => {
257 it("resolves Cmd+Shift+C on macOS and Ctrl+Shift+C elsewhere", () => {
258 assert.equal(
259 resolveShortcutCommand(event({ key: "c", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
260 platform: "MacIntel",
261 }),
262 "thread.copyReference",
263 );
264 assert.equal(
265 resolveShortcutCommand(event({ key: "c", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
266 platform: "Linux",
267 }),
268 "thread.copyReference",
269 );
270 });
271​
272 it("leaves terminal copy untouched", () => {
273 assert.isNull(
274 resolveShortcutCommand(event({ key: "c", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
275 platform: "Linux",
276 context: { terminalFocus: true },
277 }),
278 );
279 });
280});
281​
282describe("split/new/close terminal shortcuts", () => {
283 it("requires terminalFocus for default split/new/close bindings", () => {
284 assert.isFalse(
285 isTerminalSplitShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
286 platform: "MacIntel",
287 context: { terminalFocus: false },
288 }),
289 );
290 assert.isFalse(
291 isTerminalSplitVerticalShortcut(
292 event({ key: "d", metaKey: true, shiftKey: true }),
293 DEFAULT_BINDINGS,
294 {
295 platform: "MacIntel",
296 context: { terminalFocus: false },
297 },
298 ),
299 );
300 assert.isFalse(
301 isTerminalNewShortcut(event({ key: "n", ctrlKey: true }), DEFAULT_BINDINGS, {
302 platform: "Linux",
303 context: { terminalFocus: false },
304 }),
305 );
306 assert.isFalse(
307 isTerminalCloseShortcut(event({ key: "w", ctrlKey: true }), DEFAULT_BINDINGS, {
308 platform: "Linux",
309 context: { terminalFocus: false },
310 }),
311 );
312 });
313​
314 it("matches split/new when terminalFocus is true", () => {
315 assert.isTrue(
316 isTerminalSplitShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
317 platform: "MacIntel",
318 context: { terminalFocus: true },
319 }),
320 );
321 assert.isTrue(
322 isTerminalSplitVerticalShortcut(
323 event({ key: "d", metaKey: true, shiftKey: true }),
324 DEFAULT_BINDINGS,
325 {
326 platform: "MacIntel",
327 context: { terminalFocus: true },
328 },
329 ),
330 );
331 assert.isTrue(
332 isTerminalNewShortcut(event({ key: "n", ctrlKey: true }), DEFAULT_BINDINGS, {
333 platform: "Linux",
334 context: { terminalFocus: true },
335 }),
336 );
337 assert.isTrue(
338 isTerminalCloseShortcut(event({ key: "w", ctrlKey: true }), DEFAULT_BINDINGS, {
339 platform: "Linux",
340 context: { terminalFocus: true },
341 }),
342 );
343 });
344​
345 it("supports when expressions", () => {
346 const keybindings = compile([
347 {
348 shortcut: modShortcut("\\"),
349 command: "terminal.split",
350 whenAst: whenAnd(whenIdentifier("terminalOpen"), whenNot(whenIdentifier("terminalFocus"))),
351 },
352 {
353 shortcut: modShortcut("n", { shiftKey: true }),
354 command: "terminal.new",
355 whenAst: whenAnd(whenIdentifier("terminalOpen"), whenNot(whenIdentifier("terminalFocus"))),
356 },
357 { shortcut: modShortcut("j"), command: "terminal.toggle" },
358 ]);
359 assert.isTrue(
360 isTerminalSplitShortcut(event({ key: "\\", ctrlKey: true }), keybindings, {
361 platform: "Win32",
362 context: { terminalOpen: true, terminalFocus: false },
363 }),
364 );
365 assert.isFalse(
366 isTerminalSplitShortcut(event({ key: "\\", ctrlKey: true }), keybindings, {
367 platform: "Win32",
368 context: { terminalOpen: false, terminalFocus: false },
369 }),
370 );
371 assert.isTrue(
372 isTerminalNewShortcut(event({ key: "n", ctrlKey: true, shiftKey: true }), keybindings, {
373 platform: "Win32",
374 context: { terminalOpen: true, terminalFocus: false },
375 }),
376 );
377 });
378​
379 it("supports when boolean literals", () => {
380 const keybindings = compile([
381 { shortcut: modShortcut("n"), command: "terminal.new", whenAst: whenIdentifier("true") },
382 { shortcut: modShortcut("m"), command: "terminal.new", whenAst: whenIdentifier("false") },
383 ]);
384​
385 assert.isTrue(
386 isTerminalNewShortcut(event({ key: "n", ctrlKey: true }), keybindings, {
387 platform: "Linux",
388 }),
389 );
390 assert.isFalse(
391 isTerminalNewShortcut(event({ key: "m", ctrlKey: true }), keybindings, {
392 platform: "Linux",
393 }),
394 );
395 });
396});
397​
398describe("shortcutLabelForCommand", () => {
399 it("returns the effective binding label", () => {
400 const bindings = compile([
401 {
402 shortcut: modShortcut("\\"),
403 command: "terminal.split",
404 whenAst: whenIdentifier("terminalFocus"),
405 },
406 {
407 shortcut: modShortcut("\\", { shiftKey: true }),
408 command: "terminal.split",
409 whenAst: whenNot(whenIdentifier("terminalFocus")),
410 },
411 ]);
412 assert.strictEqual(
413 shortcutLabelForCommand(bindings, "terminal.split", {
414 platform: "Linux",
415 context: { terminalFocus: false },
416 }),
417 "Ctrl+Shift+\\",
418 );
419 });
420​
421 it("returns effective labels for non-terminal commands", () => {
422 assert.strictEqual(
423 shortcutLabelForCommand(DEFAULT_BINDINGS, "sidebar.toggle", "MacIntel"),
424 "⌘B",
425 );
426 assert.strictEqual(shortcutLabelForCommand(DEFAULT_BINDINGS, "chat.new", "MacIntel"), "⇧⌘O");
427 assert.strictEqual(shortcutLabelForCommand(DEFAULT_BINDINGS, "diff.toggle", "Linux"), "Ctrl+D");
428 assert.strictEqual(
429 shortcutLabelForCommand(DEFAULT_BINDINGS, "rightPanel.toggle", "MacIntel"),
430 "⌥⌘B",
431 );
432 assert.strictEqual(
433 shortcutLabelForCommand(DEFAULT_BINDINGS, "commandPalette.toggle", "MacIntel"),
434 "⌘K",
435 );
436 assert.strictEqual(
437 shortcutLabelForCommand(DEFAULT_BINDINGS, "filePicker.toggle", "MacIntel"),
438 "⌘P",
439 );
440 assert.strictEqual(
441 shortcutLabelForCommand(DEFAULT_BINDINGS, "projectSearch.toggle", "MacIntel"),
442 "⇧⌘F",
443 );
444 assert.strictEqual(
445 shortcutLabelForCommand(DEFAULT_BINDINGS, "modelPicker.toggle", "Linux"),
446 "Ctrl+Shift+M",
447 );
448 assert.strictEqual(
449 shortcutLabelForCommand(DEFAULT_BINDINGS, "editor.openFavorite", "Linux"),
450 "Ctrl+O",
451 );
452 assert.strictEqual(
453 shortcutLabelForCommand(DEFAULT_BINDINGS, "thread.jump.3", "MacIntel"),
454 "⌘3",
455 );
456 assert.strictEqual(
457 shortcutLabelForCommand(DEFAULT_BINDINGS, "thread.previous", "Linux"),
458 "Ctrl+Shift+[",
459 );
460 assert.strictEqual(
461 shortcutLabelForCommand(DEFAULT_BINDINGS, "modelPicker.jump.3", {
462 platform: "MacIntel",
463 context: { modelPickerOpen: true },
464 }),
465 "⌘3",
466 );
467 });
468​
469 it("returns null for commands shadowed by a later conflicting shortcut", () => {
470 const bindings = compile([
471 { shortcut: modShortcut("1", { shiftKey: true }), command: "thread.jump.1" },
472 { shortcut: modShortcut("1", { shiftKey: true }), command: "thread.jump.7" },
473 ]);
474​
475 assert.isNull(shortcutLabelForCommand(bindings, "thread.jump.1", "MacIntel"));
476 assert.strictEqual(shortcutLabelForCommand(bindings, "thread.jump.7", "MacIntel"), "⇧⌘1");
477 });
478​
479 it("respects when-context while resolving labels", () => {
480 const bindings = compile([
481 { shortcut: modShortcut("d"), command: "diff.toggle" },
482 {
483 shortcut: modShortcut("d"),
484 command: "terminal.split",
485 whenAst: whenIdentifier("terminalFocus"),
486 },
487 ]);
488​
489 assert.strictEqual(
490 shortcutLabelForCommand(bindings, "diff.toggle", {
491 platform: "Linux",
492 context: { terminalFocus: false },
493 }),
494 "Ctrl+D",
495 );
496 assert.isNull(
497 shortcutLabelForCommand(bindings, "diff.toggle", {
498 platform: "Linux",
499 context: { terminalFocus: true },
500 }),
501 );
502 assert.strictEqual(
503 shortcutLabelForCommand(bindings, "terminal.split", {
504 platform: "Linux",
505 context: { terminalFocus: true },
506 }),
507 "Ctrl+D",
508 );
509 });
510});
511​
512describe("thread navigation helpers", () => {
513 it("maps jump commands to visible thread indices", () => {
514 assert.strictEqual(threadJumpCommandForIndex(0), "thread.jump.1");
515 assert.strictEqual(threadJumpCommandForIndex(2), "thread.jump.3");
516 assert.isNull(threadJumpCommandForIndex(9));
517 assert.strictEqual(threadJumpIndexFromCommand("thread.jump.1"), 0);
518 assert.strictEqual(threadJumpIndexFromCommand("thread.jump.3"), 2);
519 assert.isNull(threadJumpIndexFromCommand("thread.next"));
520 });
521​
522 it("maps traversal commands to directions", () => {
523 assert.strictEqual(threadTraversalDirectionFromCommand("thread.previous"), "previous");
524 assert.strictEqual(threadTraversalDirectionFromCommand("thread.next"), "next");
525 assert.isNull(threadTraversalDirectionFromCommand("thread.jump.1"));
526 assert.isNull(threadTraversalDirectionFromCommand(null));
527 });
528​
529 it("shows jump hints only when configured modifiers match", () => {
530 assert.isTrue(
531 shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {
532 platform: "MacIntel",
533 }),
534 );
535 assert.isFalse(
536 shouldShowThreadJumpHintsForModifiers(
537 event({ metaKey: true, shiftKey: true }),
538 DEFAULT_BINDINGS,
539 {
540 platform: "MacIntel",
541 },
542 ),
543 );
544 assert.isTrue(
545 shouldShowThreadJumpHintsForModifiers(event({ ctrlKey: true }), DEFAULT_BINDINGS, {
546 platform: "Linux",
547 }),
548 );
549 });
550​
551 it("never shows jump hints while the terminal is focused, even with an unrestricted binding", () => {
552 assert.isFalse(
553 shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {
554 platform: "MacIntel",
555 context: { terminalFocus: true },
556 }),
557 );
558 assert.isTrue(
559 shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {
560 platform: "MacIntel",
561 context: { terminalFocus: false },
562 }),
563 );
564 });
565​
566 it("keeps default thread jumps off the web so the browser can switch tabs", () => {
567 const input = event({ key: "1", metaKey: true });
568 assert.isNull(
569 resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
570 platform: "MacIntel",
571 context: { isDesktop: false },
572 }),
573 );
574 assert.strictEqual(
575 resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
576 platform: "MacIntel",
577 context: { isDesktop: true },
578 }),
579 "thread.jump.1",
580 );
581 assert.isFalse(
582 shouldShowThreadJumpHintsForModifiers(
583 event({ metaKey: true }),
584 DEFAULT_RESOLVED_KEYBINDINGS,
585 {
586 platform: "MacIntel",
587 context: { isDesktop: false },
588 },
589 ),
590 );
591 assert.isTrue(
592 shouldShowThreadJumpHintsForModifiers(
593 event({ metaKey: true }),
594 DEFAULT_RESOLVED_KEYBINDINGS,
595 {
596 platform: "MacIntel",
597 context: { isDesktop: true },
598 },
599 ),
600 );
601 });
602});
603​
604describe("model picker navigation helpers", () => {
605 it("maps jump commands to visible model indices", () => {
606 assert.strictEqual(modelPickerJumpCommandForIndex(0), "modelPicker.jump.1");
607 assert.strictEqual(modelPickerJumpCommandForIndex(2), "modelPicker.jump.3");
608 assert.isNull(modelPickerJumpCommandForIndex(9));
609 assert.strictEqual(modelPickerJumpIndexFromCommand("modelPicker.jump.1"), 0);
610 assert.strictEqual(modelPickerJumpIndexFromCommand("modelPicker.jump.3"), 2);
611 assert.isNull(modelPickerJumpIndexFromCommand("thread.jump.1"));
612 });
613​
614 it("keeps default model jumps off the web even while the picker is open", () => {
615 const input = event({ key: "3", metaKey: true });
616 assert.isNull(
617 resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
618 platform: "MacIntel",
619 context: { isDesktop: false, modelPickerOpen: true },
620 }),
621 );
622 assert.strictEqual(
623 resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
624 platform: "MacIntel",
625 context: { isDesktop: true, modelPickerOpen: true },
626 }),
627 "modelPicker.jump.3",
628 );
629 assert.strictEqual(
630 resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
631 platform: "MacIntel",
632 context: { isDesktop: true, modelPickerOpen: false },
633 }),
634 "thread.jump.3",
635 );
636 });
637});
638​
639describe("chat/editor shortcuts", () => {
640 it("matches chat.new shortcut", () => {
641 assert.strictEqual(
642 resolveShortcutCommand(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
643 platform: "MacIntel",
644 }),
645 "chat.new",
646 );
647 assert.strictEqual(
648 resolveShortcutCommand(event({ key: "o", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
649 platform: "Linux",
650 }),
651 "chat.new",
652 );
653 });
654​
655 it("matches chat.newLocal shortcut", () => {
656 assert.strictEqual(
657 resolveShortcutCommand(event({ key: "n", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
658 platform: "MacIntel",
659 }),
660 "chat.newLocal",
661 );
662 assert.strictEqual(
663 resolveShortcutCommand(event({ key: "n", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
664 platform: "Linux",
665 }),
666 "chat.newLocal",
667 );
668 });
669​
670 it("matches editor.openFavorite shortcut", () => {
671 assert.isTrue(
672 isOpenFavoriteEditorShortcut(event({ key: "o", metaKey: true }), DEFAULT_BINDINGS, {
673 platform: "MacIntel",
674 }),
675 );
676 assert.isTrue(
677 isOpenFavoriteEditorShortcut(event({ key: "o", ctrlKey: true }), DEFAULT_BINDINGS, {
678 platform: "Linux",
679 }),
680 );
681 });
682​
683 it("matches commandPalette.toggle shortcut outside terminal focus", () => {
684 assert.strictEqual(
685 resolveShortcutCommand(event({ key: "k", metaKey: true }), DEFAULT_BINDINGS, {
686 platform: "MacIntel",
687 context: { terminalFocus: false },
688 }),
689 "commandPalette.toggle",
690 );
691 assert.notStrictEqual(
692 resolveShortcutCommand(event({ key: "k", metaKey: true }), DEFAULT_BINDINGS, {
693 platform: "MacIntel",
694 context: { terminalFocus: true },
695 }),
696 "commandPalette.toggle",
697 );
698 });
699​
700 it("matches filePicker.toggle shortcut outside terminal focus", () => {
701 assert.strictEqual(
702 resolveShortcutCommand(event({ key: "p", metaKey: true }), DEFAULT_BINDINGS, {
703 platform: "MacIntel",
704 context: { terminalFocus: false },
705 }),
706 "filePicker.toggle",
707 );
708 assert.notStrictEqual(
709 resolveShortcutCommand(event({ key: "p", metaKey: true }), DEFAULT_BINDINGS, {
710 platform: "MacIntel",
711 context: { terminalFocus: true },
712 }),
713 "filePicker.toggle",
714 );
715 });
716​
717 it("matches projectSearch.toggle shortcut outside terminal focus", () => {
718 assert.strictEqual(
719 resolveShortcutCommand(event({ key: "f", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
720 platform: "MacIntel",
721 context: { terminalFocus: false },
722 }),
723 "projectSearch.toggle",
724 );
725 assert.notStrictEqual(
726 resolveShortcutCommand(event({ key: "f", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
727 platform: "MacIntel",
728 context: { terminalFocus: true },
729 }),
730 "projectSearch.toggle",
731 );
732 });
733​
734 it("matches themeEditor.toggle on macOS and Windows", () => {
735 assert.strictEqual(
736 resolveShortcutCommand(
737 event({ key: "t", metaKey: true, altKey: true, shiftKey: true }),
738 DEFAULT_BINDINGS,
739 { platform: "MacIntel" },
740 ),
741 "themeEditor.toggle",
742 );
743 assert.strictEqual(
744 resolveShortcutCommand(
745 event({ key: "t", ctrlKey: true, altKey: true, shiftKey: true }),
746 DEFAULT_BINDINGS,
747 { platform: "Win32" },
748 ),
749 "themeEditor.toggle",
750 );
751 });
752​
753 it("matches diff.toggle shortcut outside terminal focus", () => {
754 assert.isTrue(
755 isDiffToggleShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
756 platform: "MacIntel",
757 context: { terminalFocus: false },
758 }),
759 );
760 assert.isFalse(
761 isDiffToggleShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
762 platform: "MacIntel",
763 context: { terminalFocus: true },
764 }),
765 );
766 });
767});
768​
769describe("cross-command precedence", () => {
770 it("uses when + order so a later focused rule overrides a global rule", () => {
771 const keybindings = compile([
772 { shortcut: modShortcut("n"), command: "chat.new" },
773 {
774 shortcut: modShortcut("n"),
775 command: "terminal.new",
776 whenAst: whenIdentifier("terminalFocus"),
777 },
778 ]);
779​
780 assert.isTrue(
781 isTerminalNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
782 platform: "MacIntel",
783 context: { terminalFocus: true },
784 }),
785 );
786 assert.strictEqual(
787 resolveShortcutCommand(event({ key: "n", metaKey: true }), keybindings, {
788 platform: "MacIntel",
789 context: { terminalFocus: true },
790 }),
791 "terminal.new",
792 );
793 assert.isFalse(
794 isTerminalNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
795 platform: "MacIntel",
796 context: { terminalFocus: false },
797 }),
798 );
799 assert.strictEqual(
800 resolveShortcutCommand(event({ key: "n", metaKey: true }), keybindings, {
801 platform: "MacIntel",
802 context: { terminalFocus: false },
803 }),
804 "chat.new",
805 );
806 });
807​
808 it("still lets a later global rule win when both rules match", () => {
809 const keybindings = compile([
810 {
811 shortcut: modShortcut("n"),
812 command: "terminal.new",
813 whenAst: whenIdentifier("terminalFocus"),
814 },
815 { shortcut: modShortcut("n"), command: "chat.new" },
816 ]);
817​
818 assert.isFalse(
819 isTerminalNewShortcut(event({ key: "n", ctrlKey: true }), keybindings, {
820 platform: "Linux",
821 context: { terminalFocus: true },
822 }),
823 );
824 assert.strictEqual(
825 resolveShortcutCommand(event({ key: "n", ctrlKey: true }), keybindings, {
826 platform: "Linux",
827 context: { terminalFocus: true },
828 }),
829 "chat.new",
830 );
831 });
832});
833​
834describe("resolveShortcutCommand", () => {
835 it("resolves a custom stop-thread shortcut", () => {
836 const keybindings = compile([{ shortcut: modShortcut("escape"), command: "thread.stop" }]);
837​
838 assert.strictEqual(
839 resolveShortcutCommand(event({ key: "Escape", metaKey: true }), keybindings, {
840 platform: "MacIntel",
841 }),
842 "thread.stop",
843 );
844 });
845​
846 it("honors preview conditions for a stop-thread shortcut", () => {
847 const keybindings = compile([
848 {
849 shortcut: modShortcut("escape"),
850 command: "thread.stop",
851 whenAst: whenIdentifier("previewFocus"),
852 },
853 ]);
854 const input = event({ key: "Escape", metaKey: true });
855​
856 assert.isNull(
857 resolveShortcutCommand(input, keybindings, {
858 platform: "MacIntel",
859 context: { previewFocus: false },
860 }),
861 );
862 assert.strictEqual(
863 resolveShortcutCommand(input, keybindings, {
864 platform: "MacIntel",
865 context: { previewFocus: true },
866 }),
867 "thread.stop",
868 );
869 });
870​
871 it("returns dynamic script commands", () => {
872 const keybindings = compile([{ shortcut: modShortcut("r"), command: "script.setup.run" }]);
873​
874 assert.strictEqual(
875 resolveShortcutCommand(event({ key: "r", ctrlKey: true }), keybindings, {
876 platform: "Linux",
877 }),
878 "script.setup.run",
879 );
880 });
881​
882 it("routes mod+w to the terminal while focused and to the right panel otherwise", () => {
883 const closeEvent = event({ key: "w", metaKey: true });
884 assert.strictEqual(
885 resolveShortcutCommand(closeEvent, DEFAULT_BINDINGS, {
886 platform: "MacIntel",
887 context: { terminalFocus: true },
888 }),
889 "terminal.close",
890 );
891 assert.strictEqual(
892 resolveShortcutCommand(closeEvent, DEFAULT_BINDINGS, {
893 platform: "MacIntel",
894 context: { terminalFocus: false },
895 }),
896 "rightPanel.close",
897 );
898 });
899​
900 it("resolves a custom right panel maximize binding", () => {
901 const keybindings = compile([
902 {
903 shortcut: modShortcut("m", { shiftKey: true }),
904 command: "rightPanel.toggleMaximized",
905 },
906 ]);
907​
908 assert.strictEqual(
909 resolveShortcutCommand(event({ key: "m", metaKey: true, shiftKey: true }), keybindings, {
910 platform: "MacIntel",
911 }),
912 "rightPanel.toggleMaximized",
913 );
914 });
915​
916 it("navigates history with mod+[ and mod+] outside the terminal", () => {
917 const back = event({ key: "[", code: "BracketLeft", metaKey: true });
918 const forward = event({ key: "]", code: "BracketRight", ctrlKey: true });
919 assert.strictEqual(
920 resolveShortcutCommand(back, DEFAULT_RESOLVED_KEYBINDINGS, { platform: "MacIntel" }),
921 "navigation.back",
922 );
923 assert.strictEqual(
924 resolveShortcutCommand(forward, DEFAULT_RESOLVED_KEYBINDINGS, { platform: "Linux" }),
925 "navigation.forward",
926 );
927 assert.isNull(
928 resolveShortcutCommand(back, DEFAULT_RESOLVED_KEYBINDINGS, {
929 platform: "MacIntel",
930 context: { terminalFocus: true },
931 }),
932 );
933 });
934​
935 it("matches bracket shortcuts using the physical key code", () => {
936 assert.strictEqual(
937 resolveShortcutCommand(
938 event({ key: "{", code: "BracketLeft", metaKey: true, shiftKey: true }),
939 DEFAULT_BINDINGS,
940 {
941 platform: "MacIntel",
942 },
943 ),
944 "thread.previous",
945 );
946 assert.strictEqual(
947 resolveShortcutCommand(
948 event({ key: "}", code: "BracketRight", ctrlKey: true, shiftKey: true }),
949 DEFAULT_BINDINGS,
950 {
951 platform: "Linux",
952 },
953 ),
954 "thread.next",
955 );
956 });
957​
958 it("matches punctuation shortcuts by physical key across keyboard layouts", () => {
959 const keybindings = compile([
960 { shortcut: modShortcut("'", { shiftKey: true }), command: "diff.toggle" },
961 ]);
962​
963 assert.strictEqual(
964 resolveShortcutCommand(
965 event({ key: "@", code: "Quote", metaKey: true, shiftKey: true }),
966 keybindings,
967 { platform: "MacIntel" },
968 ),
969 "diff.toggle",
970 );
971 assert.isNull(
972 resolveShortcutCommand(
973 event({ key: '"', code: "Digit2", metaKey: true, shiftKey: true }),
974 keybindings,
975 { platform: "MacIntel" },
976 ),
977 );
978 });
979​
980 it("does not let a punctuation position shadow a Latin layout key", () => {
981 const keybindings = compile([
982 { shortcut: modShortcut("m"), command: "diff.toggle" },
983 { shortcut: modShortcut(";"), command: "sidebar.toggle" },
984 ]);
985​
986 assert.strictEqual(
987 resolveShortcutCommand(event({ key: "m", code: "Semicolon", metaKey: true }), keybindings, {
988 platform: "MacIntel",
989 }),
990 "diff.toggle",
991 );
992 });
993​
994 it("matches Option-modified letters using the physical key code on macOS", () => {
995 assert.strictEqual(
996 resolveShortcutCommand(
997 event({ key: "∫", code: "KeyB", metaKey: true, altKey: true }),
998 DEFAULT_BINDINGS,
999 { platform: "MacIntel" },
1000 ),
1001 "rightPanel.toggle",
1002 );
1003 });
1004​
1005 it("matches non-Latin layout letters using the physical key code", () => {
1006 const keybindings = compile([{ shortcut: modShortcut("d"), command: "diff.toggle" }]);
1007​
1008 assert.strictEqual(
1009 resolveShortcutCommand(event({ key: "в", code: "KeyD", metaKey: true }), keybindings, {
1010 platform: "MacIntel",
1011 }),
1012 "diff.toggle",
1013 );
1014 });
1015​
1016 it("ignores the physical key code when the layout types a different Latin letter", () => {
1017 const keybindings = compile([{ shortcut: modShortcut("d"), command: "diff.toggle" }]);
1018​
1019 // On a remapped layout the physical D key types "a"; only the physical
1020 // key whose layout output is "d" may trigger the shortcut.
1021 assert.isNull(
1022 resolveShortcutCommand(event({ key: "a", code: "KeyD", metaKey: true }), keybindings, {
1023 platform: "MacIntel",
1024 }),
1025 );
1026 assert.strictEqual(
1027 resolveShortcutCommand(event({ key: "d", code: "KeyL", metaKey: true }), keybindings, {
1028 platform: "MacIntel",
1029 }),
1030 "diff.toggle",
1031 );
1032 });
1033});
1034​
1035describe("formatShortcutLabel", () => {
1036 it("formats labels for macOS", () => {
1037 assert.strictEqual(
1038 formatShortcutLabel(modShortcut("d", { shiftKey: true }), "MacIntel"),
1039 "⇧⌘D",
1040 );
1041 });
1042​
1043 it("formats labels for non-macOS", () => {
1044 assert.strictEqual(
1045 formatShortcutLabel(modShortcut("d", { shiftKey: true }), "Linux"),
1046 "Ctrl+Shift+D",
1047 );
1048 });
1049​
1050 it("formats labels for plus key", () => {
1051 assert.strictEqual(formatShortcutLabel(modShortcut("+"), "MacIntel"), "⌘+");
1052 assert.strictEqual(formatShortcutLabel(modShortcut("+"), "Linux"), "Ctrl++");
1053 });
1054});
1055​
1056describe("isTerminalClearShortcut", () => {
1057 it("matches Ctrl+L on all platforms", () => {
1058 assert.isTrue(isTerminalClearShortcut(event({ key: "l", ctrlKey: true }), "Linux"));
1059 assert.isTrue(isTerminalClearShortcut(event({ key: "l", ctrlKey: true }), "MacIntel"));
1060 });
1061​
1062 it("matches Cmd+K on macOS", () => {
1063 assert.isTrue(isTerminalClearShortcut(event({ key: "k", metaKey: true }), "MacIntel"));
1064 });
1065​
1066 it("ignores non-keydown events", () => {
1067 assert.isFalse(
1068 isTerminalClearShortcut(event({ type: "keyup", key: "l", ctrlKey: true }), "Linux"),
1069 );
1070 });
1071});
1072​
1073describe("isRichTextBoldShortcut", () => {
1074 it("matches Mod+B without extra modifiers", () => {
1075 assert.isTrue(isRichTextBoldShortcut(event({ key: "b", metaKey: true })));
1076 assert.isTrue(isRichTextBoldShortcut(event({ key: "B", ctrlKey: true })));
1077 });
1078​
1079 it("ignores shifted, alted, bare, and non-keydown presses", () => {
1080 assert.isFalse(isRichTextBoldShortcut(event({ key: "b", metaKey: true, shiftKey: true })));
1081 assert.isFalse(isRichTextBoldShortcut(event({ key: "b", metaKey: true, altKey: true })));
1082 assert.isFalse(isRichTextBoldShortcut(event({ key: "b" })));
1083 assert.isFalse(isRichTextBoldShortcut(event({ key: "i", metaKey: true })));
1084 assert.isFalse(isRichTextBoldShortcut(event({ type: "keyup", key: "b", metaKey: true })));
1085 });
1086});
1087​
1088describe("terminalDeleteShortcutData", () => {
1089 it("maps Cmd+Backspace on macOS to delete-to-line-start", () => {
1090 assert.strictEqual(
1091 terminalDeleteShortcutData(event({ key: "Backspace", metaKey: true }), "MacIntel"),
1092 "\u0015",
1093 );
1094 });
1095​
1096 it("ignores non-macOS platforms and modified variants", () => {
1097 assert.isNull(terminalDeleteShortcutData(event({ key: "Backspace", metaKey: true }), "Linux"));
1098 assert.isNull(
1099 terminalDeleteShortcutData(
1100 event({ key: "Backspace", metaKey: true, altKey: true }),
1101 "MacIntel",
1102 ),
1103 );
1104 });
1105​
1106 it("ignores non-keydown events", () => {
1107 assert.isNull(
1108 terminalDeleteShortcutData(
1109 event({ type: "keyup", key: "Backspace", metaKey: true }),
1110 "MacIntel",
1111 ),
1112 );
1113 });
1114});
1115​
1116describe("terminalNavigationShortcutData", () => {
1117 it("maps Option+Arrow on macOS to word movement", () => {
1118 assert.strictEqual(
1119 terminalNavigationShortcutData(event({ key: "ArrowLeft", altKey: true }), "MacIntel"),
1120 "\u001bb",
1121 );
1122 assert.strictEqual(
1123 terminalNavigationShortcutData(event({ key: "ArrowRight", altKey: true }), "MacIntel"),
1124 "\u001bf",
1125 );
1126 });
1127​
1128 it("maps Cmd+Arrow on macOS to line movement", () => {
1129 assert.strictEqual(
1130 terminalNavigationShortcutData(event({ key: "ArrowLeft", metaKey: true }), "MacIntel"),
1131 "\u0001",
1132 );
1133 assert.strictEqual(
1134 terminalNavigationShortcutData(event({ key: "ArrowRight", metaKey: true }), "MacIntel"),
1135 "\u0005",
1136 );
1137 });
1138​
1139 it("maps Ctrl+Arrow on non-macOS to word movement", () => {
1140 assert.strictEqual(
1141 terminalNavigationShortcutData(event({ key: "ArrowLeft", ctrlKey: true }), "Win32"),
1142 "\u001bb",
1143 );
1144 assert.strictEqual(
1145 terminalNavigationShortcutData(event({ key: "ArrowRight", ctrlKey: true }), "Linux"),
1146 "\u001bf",
1147 );
1148 });
1149​
1150 it("rejects unsupported combinations", () => {
1151 assert.isNull(
1152 terminalNavigationShortcutData(
1153 event({ key: "ArrowLeft", shiftKey: true, altKey: true }),
1154 "MacIntel",
1155 ),
1156 );
1157 assert.isNull(
1158 terminalNavigationShortcutData(event({ key: "ArrowLeft", metaKey: true }), "Linux"),
1159 );
1160 assert.isNull(terminalNavigationShortcutData(event({ key: "a", altKey: true }), "MacIntel"));
1161 });
1162​
1163 it("ignores non-keydown events", () => {
1164 assert.isNull(
1165 terminalNavigationShortcutData(
1166 event({ type: "keyup", key: "ArrowLeft", altKey: true }),
1167 "MacIntel",
1168 ),
1169 );
1170 });
1171});
1172​
1173describe("plus key parsing", () => {
1174 it("matches the plus key shortcut", () => {
1175 const plusBindings = compile([{ shortcut: modShortcut("+"), command: "terminal.toggle" }]);
1176 assert.isTrue(
1177 isTerminalToggleShortcut(event({ key: "+", metaKey: true }), plusBindings, {
1178 platform: "MacIntel",
1179 }),
1180 );
1181 assert.isTrue(
1182 isTerminalToggleShortcut(event({ key: "+", ctrlKey: true }), plusBindings, {
1183 platform: "Linux",
1184 }),
1185 );
1186 });
1187});
1188​
1189describe("composer and pull request shortcuts", () => {
1190 it("fills missing number shortcuts without replacing the saved URL binding", () => {
1191 const olderServerBindings = DEFAULT_RESOLVED_KEYBINDINGS.filter(
1192 (binding) =>
1193 binding.command !== "pullRequest.copyNumber" && binding.command !== "thread.copyReference",
1194 );
1195 const bindings = mergeWithDefaultKeybindings([
1196 ...olderServerBindings,
1197 ...compileResolvedKeybindingsConfig([
1198 { key: "mod+shift+8", command: "thread.copyReference", when: "!terminalFocus" },
1199 ]),
1200 ]);
1201 for (const [key, command] of [
1202 ["k", "pullRequest.copyNumber"],
1203 ["8", "thread.copyReference"],
1204 ["c", null],
1205 ["y", null],
1206 ] as const) {
1207 assert.strictEqual(
1208 resolveShortcutCommand(event({ key, metaKey: true, shiftKey: true }), bindings, {
1209 platform: "MacIntel",
1210 }),
1211 command,
1212 );
1214 });
1215​
1216 it.each(["terminalOpen", "previewFocus", "previewOpen", "modelPickerOpen", "isWeb", "isDesktop"])(
1217 "honors custom PR shortcut conditions for %s",
1218 (condition) => {
1219 const bindings = compileResolvedKeybindingsConfig([
1220 { key: "mod+shift+k", command: "thread.copyReference", when: condition },
1221 { key: "mod+shift+k", command: "pullRequest.copyNumber", when: `!${condition}` },
1222 ]);
1223 const input = event({ key: "k", ctrlKey: true, shiftKey: true });
1224 for (const enabled of [false, true]) {
1225 assert.strictEqual(
1226 resolveShortcutCommand(input, bindings, {
1227 platform: "Linux",
1228 context: { [condition]: enabled },
1229 }),
1230 enabled ? "thread.copyReference" : "pullRequest.copyNumber",
1231 );
1233 },
1234 );
1235​
1236 const shortcuts = [
1237 ["h", "composer.host"],
1238 ["e", "composer.effort"],
1239 ["a", "composer.mode"],
1240 ["x", "composer.workspace"],
1241 ["g", "composer.branch"],
1242 ["l", "composer.previousWorktree"],
1243 ["c", "thread.copyReference"],
1244 ["k", "pullRequest.copyNumber"],
1245 ["Enter", "thread.steerQueuedMessage"],
1246 ] as const;
1247​
1248 for (const platform of ["MacIntel", "Win32", "Linux"]) {
1249 it.each(shortcuts)(
1250 `resolves %s on ${platform} and leaves terminal input alone`,
1251 (key, command) => {
1252 const input = event({
1253 key,
1254 shiftKey: true,
1255 metaKey: platform === "MacIntel",
1256 ctrlKey: platform !== "MacIntel",
1257 });
1258 assert.strictEqual(
1259 resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
1260 platform,
1261 context: { terminalFocus: false },
1262 }),
1263 command,
1264 );
1265 assert.isNull(
1266 resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
1267 platform,
1268 context: { terminalFocus: true },
1269 }),
1270 );
1271 },
1272 );
1274​
1275 for (const platform of ["MacIntel", "Win32", "Linux"]) {
1276 it.each([
1277 ["s", "thread.settle"],
1278 ["p", "thread.pin"],
1279 ])(`preserves the existing %s shortcut on ${platform}`, (key, command) => {
1280 assert.strictEqual(
1281 resolveShortcutCommand(
1282 event({
1283 key,
1284 shiftKey: true,
1285 metaKey: platform === "MacIntel",
1286 ctrlKey: platform !== "MacIntel",
1287 }),
1288 DEFAULT_RESOLVED_KEYBINDINGS,
1289 { platform },
1290 ),
1291 command,
1292 );
1293 });
1295​
1296 const altEffortBindings = compileResolvedKeybindingsConfig([
1297 { key: "mod+alt+e", command: "composer.effort", when: "!terminalFocus" },
1298 ]);
1299​
1300 it("leaves AltGr text entry alone with a custom Alt binding", () => {
1301 for (const platform of ["Win32", "Linux"]) {
1302 const input = event({
1303 key: "€",
1304 code: "KeyE",
1305 ctrlKey: true,
1306 altKey: true,
1307 getModifierState: (key) => key === "AltGraph",
1308 });
1309 assert.isNull(resolveShortcutCommand(input, altEffortBindings, { platform }));
1310 assert.strictEqual(
1311 resolveShortcutCommand({ ...input, getModifierState: () => false }, altEffortBindings, {
1312 platform,
1313 }),
1314 "composer.effort",
1315 );
1317 });
1318​
1319 it("keeps Firefox modifier reporting usable on Windows and macOS", () => {
1320 const getModifierState = (key: string) => key === "AltGraph";
1321 assert.strictEqual(
1322 resolveShortcutCommand(
1323 event({ key: "e", ctrlKey: true, altKey: true, getModifierState }),
1324 altEffortBindings,
1325 { platform: "Win32" },
1326 ),
1327 "composer.effort",
1328 );
1329 assert.strictEqual(
1330 resolveShortcutCommand(
1331 event({ key: "´", code: "KeyE", metaKey: true, altKey: true, getModifierState }),
1332 altEffortBindings,
1333 { platform: "MacIntel" },
1334 ),
1335 "composer.effort",
1336 );
1337 });
1338​
1339 it.each(shortcuts)("uses a custom binding for %s", (_key, command) => {
1340 const bindings = compileResolvedKeybindingsConfig([
1341 { key: "mod+shift+y", command, when: "!terminalFocus" },
1342 ]);
1343 assert.strictEqual(
1344 resolveShortcutCommand(
1345 event({ key: "Y", code: "KeyY", ctrlKey: true, shiftKey: true }),
1346 bindings,
1347 { platform: "Linux" },
1348 ),
1349 command,
1350 );
1351 });
1352​
1353 for (const platform of ["MacIntel", "Win32", "Linux"]) {
1354 it.each([
1355 ["ArrowUp", "modelPicker.previousProvider"],
1356 ["ArrowDown", "modelPicker.nextProvider"],
1357 ] as const)(`limits %s to the model picker on ${platform}`, (key, command) => {
1358 const input = event({
1359 key,
1360 shiftKey: true,
1361 metaKey: platform === "MacIntel",
1362 ctrlKey: platform !== "MacIntel",
1363 });
1364 assert.strictEqual(
1365 resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
1366 platform,
1367 context: { modelPickerOpen: true },
1368 }),
1369 command,
1370 );
1371 assert.isNull(
1372 resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
1373 platform,
1374 context: { modelPickerOpen: false },
1375 }),
1376 );
1377 });
1379});