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

keybindings.test.ts

732 lines21.9 KB

1import { assert, describe, it } from "vite-plus/test";
2​
3import {
4 type KeybindingCommand,
5 type KeybindingShortcut,
6 type KeybindingWhenNode,
7 type ResolvedKeybindingsConfig,
8} from "@t3tools/contracts";
9import {
10 formatShortcutLabel,
11 isChatNewShortcut,
12 isChatNewLocalShortcut,
13 isDiffToggleShortcut,
14 modelPickerJumpCommandForIndex,
15 modelPickerJumpIndexFromCommand,
16 isOpenFavoriteEditorShortcut,
17 isTerminalClearShortcut,
18 isTerminalCloseShortcut,
19 isTerminalNewShortcut,
20 isTerminalSplitShortcut,
21 isTerminalToggleShortcut,
22 resolveShortcutCommand,
23 shouldShowModelPickerJumpHints,
24 shouldShowThreadJumpHints,
25 shortcutLabelForCommand,
26 terminalDeleteShortcutData,
27 terminalNavigationShortcutData,
28 threadJumpCommandForIndex,
29 threadJumpIndexFromCommand,
30 threadTraversalDirectionFromCommand,
31 type ShortcutEventLike,
32} from "./keybindings";
33​
34function event(overrides: Partial<ShortcutEventLike> = {}): ShortcutEventLike {
35 return {
36 key: "j",
37 metaKey: false,
38 ctrlKey: false,
39 shiftKey: false,
40 altKey: false,
41 ...overrides,
42 };
44​
45function modShortcut(
46 key: string,
47 overrides: Partial<Omit<KeybindingShortcut, "key">> = {},
48): KeybindingShortcut {
49 return {
50 key,
51 metaKey: false,
52 ctrlKey: false,
53 shiftKey: false,
54 altKey: false,
55 modKey: true,
56 ...overrides,
57 };
59​
60function whenIdentifier(name: string): KeybindingWhenNode {
61 return { type: "identifier", name };
63​
64function whenNot(node: KeybindingWhenNode): KeybindingWhenNode {
65 return { type: "not", node };
67​
68function whenAnd(left: KeybindingWhenNode, right: KeybindingWhenNode): KeybindingWhenNode {
69 return { type: "and", left, right };
71​
72interface TestBinding {
73 shortcut: KeybindingShortcut;
74 command: KeybindingCommand;
75 whenAst?: KeybindingWhenNode;
77​
78function compile(bindings: TestBinding[]): ResolvedKeybindingsConfig {
79 return bindings.map((binding) => ({
80 command: binding.command,
81 shortcut: binding.shortcut,
82 ...(binding.whenAst ? { whenAst: binding.whenAst } : {}),
83 }));
85​
86const DEFAULT_BINDINGS = compile([
87 { shortcut: modShortcut("j"), command: "terminal.toggle" },
88 {
89 shortcut: modShortcut("d"),
90 command: "terminal.split",
91 whenAst: whenIdentifier("terminalFocus"),
92 },
93 {
94 shortcut: modShortcut("d", { shiftKey: true }),
95 command: "terminal.new",
96 whenAst: whenIdentifier("terminalFocus"),
97 },
98 {
99 shortcut: modShortcut("w"),
100 command: "terminal.close",
101 whenAst: whenIdentifier("terminalFocus"),
102 },
103 {
104 shortcut: modShortcut("d"),
105 command: "diff.toggle",
106 whenAst: whenNot(whenIdentifier("terminalFocus")),
107 },
108 {
109 shortcut: modShortcut("k"),
110 command: "commandPalette.toggle",
111 whenAst: whenNot(whenIdentifier("terminalFocus")),
112 },
113 {
114 shortcut: modShortcut("m", { shiftKey: true }),
115 command: "modelPicker.toggle",
116 whenAst: whenNot(whenIdentifier("terminalFocus")),
117 },
118 { shortcut: modShortcut("o", { shiftKey: true }), command: "chat.new" },
119 { shortcut: modShortcut("n", { shiftKey: true }), command: "chat.newLocal" },
120 { shortcut: modShortcut("o"), command: "editor.openFavorite" },
121 { shortcut: modShortcut("[", { shiftKey: true }), command: "thread.previous" },
122 { shortcut: modShortcut("]", { shiftKey: true }), command: "thread.next" },
123 { shortcut: modShortcut("1"), command: "thread.jump.1" },
124 { shortcut: modShortcut("2"), command: "thread.jump.2" },
125 { shortcut: modShortcut("3"), command: "thread.jump.3" },
126 {
127 shortcut: modShortcut("1"),
128 command: "modelPicker.jump.1",
129 whenAst: whenIdentifier("modelPickerOpen"),
130 },
131 {
132 shortcut: modShortcut("2"),
133 command: "modelPicker.jump.2",
134 whenAst: whenIdentifier("modelPickerOpen"),
135 },
136 {
137 shortcut: modShortcut("3"),
138 command: "modelPicker.jump.3",
139 whenAst: whenIdentifier("modelPickerOpen"),
140 },
141]);
142​
143describe("isTerminalToggleShortcut", () => {
144 it("matches Cmd+J on macOS", () => {
145 assert.isTrue(
146 isTerminalToggleShortcut(event({ metaKey: true }), DEFAULT_BINDINGS, {
147 platform: "MacIntel",
148 }),
149 );
150 });
151​
152 it("matches Ctrl+J on non-macOS", () => {
153 assert.isTrue(
154 isTerminalToggleShortcut(event({ ctrlKey: true }), DEFAULT_BINDINGS, { platform: "Win32" }),
155 );
156 });
157​
158 it("matches Ctrl+J on non-macOS while terminalFocus is true", () => {
159 assert.isTrue(
160 isTerminalToggleShortcut(event({ ctrlKey: true }), DEFAULT_BINDINGS, {
161 platform: "Win32",
162 context: { terminalFocus: true },
163 }),
164 );
165 });
166});
167​
168describe("split/new/close terminal shortcuts", () => {
169 it("requires terminalFocus for default split/new/close bindings", () => {
170 assert.isFalse(
171 isTerminalSplitShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
172 platform: "MacIntel",
173 context: { terminalFocus: false },
174 }),
175 );
176 assert.isFalse(
177 isTerminalNewShortcut(event({ key: "d", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
178 platform: "Linux",
179 context: { terminalFocus: false },
180 }),
181 );
182 assert.isFalse(
183 isTerminalCloseShortcut(event({ key: "w", ctrlKey: true }), DEFAULT_BINDINGS, {
184 platform: "Linux",
185 context: { terminalFocus: false },
186 }),
187 );
188 });
189​
190 it("matches split/new when terminalFocus is true", () => {
191 assert.isTrue(
192 isTerminalSplitShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
193 platform: "MacIntel",
194 context: { terminalFocus: true },
195 }),
196 );
197 assert.isTrue(
198 isTerminalNewShortcut(event({ key: "d", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
199 platform: "Linux",
200 context: { terminalFocus: true },
201 }),
202 );
203 assert.isTrue(
204 isTerminalCloseShortcut(event({ key: "w", ctrlKey: true }), DEFAULT_BINDINGS, {
205 platform: "Linux",
206 context: { terminalFocus: true },
207 }),
208 );
209 });
210​
211 it("supports when expressions", () => {
212 const keybindings = compile([
213 {
214 shortcut: modShortcut("\\"),
215 command: "terminal.split",
216 whenAst: whenAnd(whenIdentifier("terminalOpen"), whenNot(whenIdentifier("terminalFocus"))),
217 },
218 {
219 shortcut: modShortcut("n", { shiftKey: true }),
220 command: "terminal.new",
221 whenAst: whenAnd(whenIdentifier("terminalOpen"), whenNot(whenIdentifier("terminalFocus"))),
222 },
223 { shortcut: modShortcut("j"), command: "terminal.toggle" },
224 ]);
225 assert.isTrue(
226 isTerminalSplitShortcut(event({ key: "\\", ctrlKey: true }), keybindings, {
227 platform: "Win32",
228 context: { terminalOpen: true, terminalFocus: false },
229 }),
230 );
231 assert.isFalse(
232 isTerminalSplitShortcut(event({ key: "\\", ctrlKey: true }), keybindings, {
233 platform: "Win32",
234 context: { terminalOpen: false, terminalFocus: false },
235 }),
236 );
237 assert.isTrue(
238 isTerminalNewShortcut(event({ key: "n", ctrlKey: true, shiftKey: true }), keybindings, {
239 platform: "Win32",
240 context: { terminalOpen: true, terminalFocus: false },
241 }),
242 );
243 });
244​
245 it("supports when boolean literals", () => {
246 const keybindings = compile([
247 { shortcut: modShortcut("n"), command: "terminal.new", whenAst: whenIdentifier("true") },
248 { shortcut: modShortcut("m"), command: "terminal.new", whenAst: whenIdentifier("false") },
249 ]);
250​
251 assert.isTrue(
252 isTerminalNewShortcut(event({ key: "n", ctrlKey: true }), keybindings, {
253 platform: "Linux",
254 }),
255 );
256 assert.isFalse(
257 isTerminalNewShortcut(event({ key: "m", ctrlKey: true }), keybindings, {
258 platform: "Linux",
259 }),
260 );
261 });
262});
263​
264describe("shortcutLabelForCommand", () => {
265 it("returns the effective binding label", () => {
266 const bindings = compile([
267 {
268 shortcut: modShortcut("\\"),
269 command: "terminal.split",
270 whenAst: whenIdentifier("terminalFocus"),
271 },
272 {
273 shortcut: modShortcut("\\", { shiftKey: true }),
274 command: "terminal.split",
275 whenAst: whenNot(whenIdentifier("terminalFocus")),
276 },
277 ]);
278 assert.strictEqual(
279 shortcutLabelForCommand(bindings, "terminal.split", {
280 platform: "Linux",
281 context: { terminalFocus: false },
282 }),
283 "Ctrl+Shift+\\",
284 );
285 });
286​
287 it("returns effective labels for non-terminal commands", () => {
288 assert.strictEqual(shortcutLabelForCommand(DEFAULT_BINDINGS, "chat.new", "MacIntel"), "⇧⌘O");
289 assert.strictEqual(shortcutLabelForCommand(DEFAULT_BINDINGS, "diff.toggle", "Linux"), "Ctrl+D");
290 assert.strictEqual(
291 shortcutLabelForCommand(DEFAULT_BINDINGS, "commandPalette.toggle", "MacIntel"),
292 "⌘K",
293 );
294 assert.strictEqual(
295 shortcutLabelForCommand(DEFAULT_BINDINGS, "modelPicker.toggle", "Linux"),
296 "Ctrl+Shift+M",
297 );
298 assert.strictEqual(
299 shortcutLabelForCommand(DEFAULT_BINDINGS, "editor.openFavorite", "Linux"),
300 "Ctrl+O",
301 );
302 assert.strictEqual(
303 shortcutLabelForCommand(DEFAULT_BINDINGS, "thread.jump.3", "MacIntel"),
304 "⌘3",
305 );
306 assert.strictEqual(
307 shortcutLabelForCommand(DEFAULT_BINDINGS, "thread.previous", "Linux"),
308 "Ctrl+Shift+[",
309 );
310 assert.strictEqual(
311 shortcutLabelForCommand(DEFAULT_BINDINGS, "modelPicker.jump.3", {
312 platform: "MacIntel",
313 context: { modelPickerOpen: true },
314 }),
315 "⌘3",
316 );
317 });
318​
319 it("returns null for commands shadowed by a later conflicting shortcut", () => {
320 const bindings = compile([
321 { shortcut: modShortcut("1", { shiftKey: true }), command: "thread.jump.1" },
322 { shortcut: modShortcut("1", { shiftKey: true }), command: "thread.jump.7" },
323 ]);
324​
325 assert.isNull(shortcutLabelForCommand(bindings, "thread.jump.1", "MacIntel"));
326 assert.strictEqual(shortcutLabelForCommand(bindings, "thread.jump.7", "MacIntel"), "⇧⌘1");
327 });
328​
329 it("respects when-context while resolving labels", () => {
330 const bindings = compile([
331 { shortcut: modShortcut("d"), command: "diff.toggle" },
332 {
333 shortcut: modShortcut("d"),
334 command: "terminal.split",
335 whenAst: whenIdentifier("terminalFocus"),
336 },
337 ]);
338​
339 assert.strictEqual(
340 shortcutLabelForCommand(bindings, "diff.toggle", {
341 platform: "Linux",
342 context: { terminalFocus: false },
343 }),
344 "Ctrl+D",
345 );
346 assert.isNull(
347 shortcutLabelForCommand(bindings, "diff.toggle", {
348 platform: "Linux",
349 context: { terminalFocus: true },
350 }),
351 );
352 assert.strictEqual(
353 shortcutLabelForCommand(bindings, "terminal.split", {
354 platform: "Linux",
355 context: { terminalFocus: true },
356 }),
357 "Ctrl+D",
358 );
359 });
360});
361​
362describe("thread navigation helpers", () => {
363 it("maps jump commands to visible thread indices", () => {
364 assert.strictEqual(threadJumpCommandForIndex(0), "thread.jump.1");
365 assert.strictEqual(threadJumpCommandForIndex(2), "thread.jump.3");
366 assert.isNull(threadJumpCommandForIndex(9));
367 assert.strictEqual(threadJumpIndexFromCommand("thread.jump.1"), 0);
368 assert.strictEqual(threadJumpIndexFromCommand("thread.jump.3"), 2);
369 assert.isNull(threadJumpIndexFromCommand("thread.next"));
370 });
371​
372 it("maps traversal commands to directions", () => {
373 assert.strictEqual(threadTraversalDirectionFromCommand("thread.previous"), "previous");
374 assert.strictEqual(threadTraversalDirectionFromCommand("thread.next"), "next");
375 assert.isNull(threadTraversalDirectionFromCommand("thread.jump.1"));
376 assert.isNull(threadTraversalDirectionFromCommand(null));
377 });
378​
379 it("shows jump hints only when configured modifiers match", () => {
380 assert.isTrue(
381 shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
382 platform: "MacIntel",
383 }),
384 );
385 assert.isFalse(
386 shouldShowThreadJumpHints(event({ metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
387 platform: "MacIntel",
388 }),
389 );
390 assert.isTrue(
391 shouldShowThreadJumpHints(event({ ctrlKey: true }), DEFAULT_BINDINGS, {
392 platform: "Linux",
393 }),
394 );
395 });
396});
397​
398describe("model picker navigation helpers", () => {
399 it("maps jump commands to visible model indices", () => {
400 assert.strictEqual(modelPickerJumpCommandForIndex(0), "modelPicker.jump.1");
401 assert.strictEqual(modelPickerJumpCommandForIndex(2), "modelPicker.jump.3");
402 assert.isNull(modelPickerJumpCommandForIndex(9));
403 assert.strictEqual(modelPickerJumpIndexFromCommand("modelPicker.jump.1"), 0);
404 assert.strictEqual(modelPickerJumpIndexFromCommand("modelPicker.jump.3"), 2);
405 assert.isNull(modelPickerJumpIndexFromCommand("thread.jump.1"));
406 });
407​
408 it("shows jump hints only while the model picker context is active", () => {
409 assert.isFalse(
410 shouldShowModelPickerJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
411 platform: "MacIntel",
412 context: { modelPickerOpen: false },
413 }),
414 );
415 assert.isTrue(
416 shouldShowModelPickerJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
417 platform: "MacIntel",
418 context: { modelPickerOpen: true },
419 }),
420 );
421 });
422});
423​
424describe("chat/editor shortcuts", () => {
425 it("matches chat.new shortcut", () => {
426 assert.isTrue(
427 isChatNewShortcut(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
428 platform: "MacIntel",
429 }),
430 );
431 assert.isTrue(
432 isChatNewShortcut(event({ key: "o", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
433 platform: "Linux",
434 }),
435 );
436 });
437​
438 it("matches chat.newLocal shortcut", () => {
439 assert.isTrue(
440 isChatNewLocalShortcut(event({ key: "n", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
441 platform: "MacIntel",
442 }),
443 );
444 assert.isTrue(
445 isChatNewLocalShortcut(event({ key: "n", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
446 platform: "Linux",
447 }),
448 );
449 });
450​
451 it("matches editor.openFavorite shortcut", () => {
452 assert.isTrue(
453 isOpenFavoriteEditorShortcut(event({ key: "o", metaKey: true }), DEFAULT_BINDINGS, {
454 platform: "MacIntel",
455 }),
456 );
457 assert.isTrue(
458 isOpenFavoriteEditorShortcut(event({ key: "o", ctrlKey: true }), DEFAULT_BINDINGS, {
459 platform: "Linux",
460 }),
461 );
462 });
463​
464 it("matches commandPalette.toggle shortcut outside terminal focus", () => {
465 assert.strictEqual(
466 resolveShortcutCommand(event({ key: "k", metaKey: true }), DEFAULT_BINDINGS, {
467 platform: "MacIntel",
468 context: { terminalFocus: false },
469 }),
470 "commandPalette.toggle",
471 );
472 assert.notStrictEqual(
473 resolveShortcutCommand(event({ key: "k", metaKey: true }), DEFAULT_BINDINGS, {
474 platform: "MacIntel",
475 context: { terminalFocus: true },
476 }),
477 "commandPalette.toggle",
478 );
479 });
480​
481 it("matches diff.toggle shortcut outside terminal focus", () => {
482 assert.isTrue(
483 isDiffToggleShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
484 platform: "MacIntel",
485 context: { terminalFocus: false },
486 }),
487 );
488 assert.isFalse(
489 isDiffToggleShortcut(event({ key: "d", metaKey: true }), DEFAULT_BINDINGS, {
490 platform: "MacIntel",
491 context: { terminalFocus: true },
492 }),
493 );
494 });
495});
496​
497describe("cross-command precedence", () => {
498 it("uses when + order so a later focused rule overrides a global rule", () => {
499 const keybindings = compile([
500 { shortcut: modShortcut("n"), command: "chat.new" },
501 {
502 shortcut: modShortcut("n"),
503 command: "terminal.new",
504 whenAst: whenIdentifier("terminalFocus"),
505 },
506 ]);
507​
508 assert.isTrue(
509 isTerminalNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
510 platform: "MacIntel",
511 context: { terminalFocus: true },
512 }),
513 );
514 assert.isFalse(
515 isChatNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
516 platform: "MacIntel",
517 context: { terminalFocus: true },
518 }),
519 );
520 assert.isFalse(
521 isTerminalNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
522 platform: "MacIntel",
523 context: { terminalFocus: false },
524 }),
525 );
526 assert.isTrue(
527 isChatNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
528 platform: "MacIntel",
529 context: { terminalFocus: false },
530 }),
531 );
532 });
533​
534 it("still lets a later global rule win when both rules match", () => {
535 const keybindings = compile([
536 {
537 shortcut: modShortcut("n"),
538 command: "terminal.new",
539 whenAst: whenIdentifier("terminalFocus"),
540 },
541 { shortcut: modShortcut("n"), command: "chat.new" },
542 ]);
543​
544 assert.isFalse(
545 isTerminalNewShortcut(event({ key: "n", ctrlKey: true }), keybindings, {
546 platform: "Linux",
547 context: { terminalFocus: true },
548 }),
549 );
550 assert.isTrue(
551 isChatNewShortcut(event({ key: "n", ctrlKey: true }), keybindings, {
552 platform: "Linux",
553 context: { terminalFocus: true },
554 }),
555 );
556 });
557});
558​
559describe("resolveShortcutCommand", () => {
560 it("returns dynamic script commands", () => {
561 const keybindings = compile([{ shortcut: modShortcut("r"), command: "script.setup.run" }]);
562​
563 assert.strictEqual(
564 resolveShortcutCommand(event({ key: "r", ctrlKey: true }), keybindings, {
565 platform: "Linux",
566 }),
567 "script.setup.run",
568 );
569 });
570​
571 it("matches bracket shortcuts using the physical key code", () => {
572 assert.strictEqual(
573 resolveShortcutCommand(
574 event({ key: "{", code: "BracketLeft", metaKey: true, shiftKey: true }),
575 DEFAULT_BINDINGS,
576 {
577 platform: "MacIntel",
578 },
579 ),
580 "thread.previous",
581 );
582 assert.strictEqual(
583 resolveShortcutCommand(
584 event({ key: "}", code: "BracketRight", ctrlKey: true, shiftKey: true }),
585 DEFAULT_BINDINGS,
586 {
587 platform: "Linux",
588 },
589 ),
590 "thread.next",
591 );
592 });
593});
594​
595describe("formatShortcutLabel", () => {
596 it("formats labels for macOS", () => {
597 assert.strictEqual(
598 formatShortcutLabel(modShortcut("d", { shiftKey: true }), "MacIntel"),
599 "⇧⌘D",
600 );
601 });
602​
603 it("formats labels for non-macOS", () => {
604 assert.strictEqual(
605 formatShortcutLabel(modShortcut("d", { shiftKey: true }), "Linux"),
606 "Ctrl+Shift+D",
607 );
608 });
609​
610 it("formats labels for plus key", () => {
611 assert.strictEqual(formatShortcutLabel(modShortcut("+"), "MacIntel"), "⌘+");
612 assert.strictEqual(formatShortcutLabel(modShortcut("+"), "Linux"), "Ctrl++");
613 });
614});
615​
616describe("isTerminalClearShortcut", () => {
617 it("matches Ctrl+L on all platforms", () => {
618 assert.isTrue(isTerminalClearShortcut(event({ key: "l", ctrlKey: true }), "Linux"));
619 assert.isTrue(isTerminalClearShortcut(event({ key: "l", ctrlKey: true }), "MacIntel"));
620 });
621​
622 it("matches Cmd+K on macOS", () => {
623 assert.isTrue(isTerminalClearShortcut(event({ key: "k", metaKey: true }), "MacIntel"));
624 });
625​
626 it("ignores non-keydown events", () => {
627 assert.isFalse(
628 isTerminalClearShortcut(event({ type: "keyup", key: "l", ctrlKey: true }), "Linux"),
629 );
630 });
631});
632​
633describe("terminalDeleteShortcutData", () => {
634 it("maps Cmd+Backspace on macOS to delete-to-line-start", () => {
635 assert.strictEqual(
636 terminalDeleteShortcutData(event({ key: "Backspace", metaKey: true }), "MacIntel"),
637 "\u0015",
638 );
639 });
640​
641 it("ignores non-macOS platforms and modified variants", () => {
642 assert.isNull(terminalDeleteShortcutData(event({ key: "Backspace", metaKey: true }), "Linux"));
643 assert.isNull(
644 terminalDeleteShortcutData(
645 event({ key: "Backspace", metaKey: true, altKey: true }),
646 "MacIntel",
647 ),
648 );
649 });
650​
651 it("ignores non-keydown events", () => {
652 assert.isNull(
653 terminalDeleteShortcutData(
654 event({ type: "keyup", key: "Backspace", metaKey: true }),
655 "MacIntel",
656 ),
657 );
658 });
659});
660​
661describe("terminalNavigationShortcutData", () => {
662 it("maps Option+Arrow on macOS to word movement", () => {
663 assert.strictEqual(
664 terminalNavigationShortcutData(event({ key: "ArrowLeft", altKey: true }), "MacIntel"),
665 "\u001bb",
666 );
667 assert.strictEqual(
668 terminalNavigationShortcutData(event({ key: "ArrowRight", altKey: true }), "MacIntel"),
669 "\u001bf",
670 );
671 });
672​
673 it("maps Cmd+Arrow on macOS to line movement", () => {
674 assert.strictEqual(
675 terminalNavigationShortcutData(event({ key: "ArrowLeft", metaKey: true }), "MacIntel"),
676 "\u0001",
677 );
678 assert.strictEqual(
679 terminalNavigationShortcutData(event({ key: "ArrowRight", metaKey: true }), "MacIntel"),
680 "\u0005",
681 );
682 });
683​
684 it("maps Ctrl+Arrow on non-macOS to word movement", () => {
685 assert.strictEqual(
686 terminalNavigationShortcutData(event({ key: "ArrowLeft", ctrlKey: true }), "Win32"),
687 "\u001bb",
688 );
689 assert.strictEqual(
690 terminalNavigationShortcutData(event({ key: "ArrowRight", ctrlKey: true }), "Linux"),
691 "\u001bf",
692 );
693 });
694​
695 it("rejects unsupported combinations", () => {
696 assert.isNull(
697 terminalNavigationShortcutData(
698 event({ key: "ArrowLeft", shiftKey: true, altKey: true }),
699 "MacIntel",
700 ),
701 );
702 assert.isNull(
703 terminalNavigationShortcutData(event({ key: "ArrowLeft", metaKey: true }), "Linux"),
704 );
705 assert.isNull(terminalNavigationShortcutData(event({ key: "a", altKey: true }), "MacIntel"));
706 });
707​
708 it("ignores non-keydown events", () => {
709 assert.isNull(
710 terminalNavigationShortcutData(
711 event({ type: "keyup", key: "ArrowLeft", altKey: true }),
712 "MacIntel",
713 ),
714 );
715 });
716});
717​
718describe("plus key parsing", () => {
719 it("matches the plus key shortcut", () => {
720 const plusBindings = compile([{ shortcut: modShortcut("+"), command: "terminal.toggle" }]);
721 assert.isTrue(
722 isTerminalToggleShortcut(event({ key: "+", metaKey: true }), plusBindings, {
723 platform: "MacIntel",
724 }),
725 );
726 assert.isTrue(
727 isTerminalToggleShortcut(event({ key: "+", ctrlKey: true }), plusBindings, {
728 platform: "Linux",
729 }),
730 );
731 });
732});