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

keybindings.test.ts

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