authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 01:54:47-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 01:54:47-07:00
log009c13fade9dde2fe7eed068c72c579172f12e60
treee4a8e9f0eba1b718b07d907149a3e1c720a02d95
parentee150e178be5e0484a588a8fe7ad98fd6b858973
signature Signed by PGP key B5690EEEBB952194

refactor(web): test live keybinding resolvers directly (#10069)


2 files changed, 33 insertions(+), 48 deletions(-)

apps/web/src/keybindings.test.ts+33-24
...@@ -8,8 +8,6 @@ import {...@@ -8,8 +8,6 @@ import {
8} from "@t3tools/contracts";8} from "@t3tools/contracts";
9import {9import {
10 formatShortcutLabel,10 formatShortcutLabel,
11 isChatNewShortcut,
12 isChatNewLocalShortcut,
13 isDiffToggleShortcut,11 isDiffToggleShortcut,
14 modelPickerJumpCommandForIndex,12 modelPickerJumpCommandForIndex,
15 modelPickerJumpIndexFromCommand,13 modelPickerJumpIndexFromCommand,
...@@ -22,7 +20,7 @@ import {...@@ -22,7 +20,7 @@ import {
22 isTerminalToggleShortcut,20 isTerminalToggleShortcut,
23 resolveShortcutCommand,21 resolveShortcutCommand,
24 shouldShowModelPickerJumpHints,22 shouldShowModelPickerJumpHints,
25 shouldShowThreadJumpHints,23 shouldShowThreadJumpHintsForModifiers,
26 shortcutLabelForCommand,24 shortcutLabelForCommand,
27 terminalDeleteShortcutData,25 terminalDeleteShortcutData,
28 terminalNavigationShortcutData,26 terminalNavigationShortcutData,
...@@ -498,17 +496,21 @@ describe("thread navigation helpers", () => {...@@ -498,17 +496,21 @@ describe("thread navigation helpers", () => {
498496
499 it("shows jump hints only when configured modifiers match", () => {497 it("shows jump hints only when configured modifiers match", () => {
500 assert.isTrue(498 assert.isTrue(
501 shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {499 shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {
502 platform: "MacIntel",500 platform: "MacIntel",
503 }),501 }),
504 );502 );
505 assert.isFalse(503 assert.isFalse(
506 shouldShowThreadJumpHints(event({ metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {504 shouldShowThreadJumpHintsForModifiers(
507 platform: "MacIntel",505 event({ metaKey: true, shiftKey: true }),
508 }),506 DEFAULT_BINDINGS,
507 {
508 platform: "MacIntel",
509 },
510 ),
509 );511 );
510 assert.isTrue(512 assert.isTrue(
511 shouldShowThreadJumpHints(event({ ctrlKey: true }), DEFAULT_BINDINGS, {513 shouldShowThreadJumpHintsForModifiers(event({ ctrlKey: true }), DEFAULT_BINDINGS, {
512 platform: "Linux",514 platform: "Linux",
513 }),515 }),
514 );516 );
...@@ -516,13 +518,13 @@ describe("thread navigation helpers", () => {...@@ -516,13 +518,13 @@ describe("thread navigation helpers", () => {
516518
517 it("never shows jump hints while the terminal is focused, even with an unrestricted binding", () => {519 it("never shows jump hints while the terminal is focused, even with an unrestricted binding", () => {
518 assert.isFalse(520 assert.isFalse(
519 shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {521 shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {
520 platform: "MacIntel",522 platform: "MacIntel",
521 context: { terminalFocus: true },523 context: { terminalFocus: true },
522 }),524 }),
523 );525 );
524 assert.isTrue(526 assert.isTrue(
525 shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {527 shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {
526 platform: "MacIntel",528 platform: "MacIntel",
527 context: { terminalFocus: false },529 context: { terminalFocus: false },
528 }),530 }),
...@@ -558,28 +560,32 @@ describe("model picker navigation helpers", () => {...@@ -558,28 +560,32 @@ describe("model picker navigation helpers", () => {
558560
559describe("chat/editor shortcuts", () => {561describe("chat/editor shortcuts", () => {
560 it("matches chat.new shortcut", () => {562 it("matches chat.new shortcut", () => {
561 assert.isTrue(563 assert.strictEqual(
562 isChatNewShortcut(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {564 resolveShortcutCommand(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
563 platform: "MacIntel",565 platform: "MacIntel",
564 }),566 }),
567 "chat.new",
565 );568 );
566 assert.isTrue(569 assert.strictEqual(
567 isChatNewShortcut(event({ key: "o", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {570 resolveShortcutCommand(event({ key: "o", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
568 platform: "Linux",571 platform: "Linux",
569 }),572 }),
573 "chat.new",
570 );574 );
571 });575 });
572576
573 it("matches chat.newLocal shortcut", () => {577 it("matches chat.newLocal shortcut", () => {
574 assert.isTrue(578 assert.strictEqual(
575 isChatNewLocalShortcut(event({ key: "n", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {579 resolveShortcutCommand(event({ key: "n", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
576 platform: "MacIntel",580 platform: "MacIntel",
577 }),581 }),
582 "chat.newLocal",
578 );583 );
579 assert.isTrue(584 assert.strictEqual(
580 isChatNewLocalShortcut(event({ key: "n", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {585 resolveShortcutCommand(event({ key: "n", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
581 platform: "Linux",586 platform: "Linux",
582 }),587 }),
588 "chat.newLocal",
583 );589 );
584 });590 });
585591
...@@ -699,11 +705,12 @@ describe("cross-command precedence", () => {...@@ -699,11 +705,12 @@ describe("cross-command precedence", () => {
699 context: { terminalFocus: true },705 context: { terminalFocus: true },
700 }),706 }),
701 );707 );
702 assert.isFalse(708 assert.strictEqual(
703 isChatNewShortcut(event({ key: "n", metaKey: true }), keybindings, {709 resolveShortcutCommand(event({ key: "n", metaKey: true }), keybindings, {
704 platform: "MacIntel",710 platform: "MacIntel",
705 context: { terminalFocus: true },711 context: { terminalFocus: true },
706 }),712 }),
713 "terminal.new",
707 );714 );
708 assert.isFalse(715 assert.isFalse(
709 isTerminalNewShortcut(event({ key: "n", metaKey: true }), keybindings, {716 isTerminalNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
...@@ -711,11 +718,12 @@ describe("cross-command precedence", () => {...@@ -711,11 +718,12 @@ describe("cross-command precedence", () => {
711 context: { terminalFocus: false },718 context: { terminalFocus: false },
712 }),719 }),
713 );720 );
714 assert.isTrue(721 assert.strictEqual(
715 isChatNewShortcut(event({ key: "n", metaKey: true }), keybindings, {722 resolveShortcutCommand(event({ key: "n", metaKey: true }), keybindings, {
716 platform: "MacIntel",723 platform: "MacIntel",
717 context: { terminalFocus: false },724 context: { terminalFocus: false },
718 }),725 }),
726 "chat.new",
719 );727 );
720 });728 });
721729
...@@ -735,11 +743,12 @@ describe("cross-command precedence", () => {...@@ -735,11 +743,12 @@ describe("cross-command precedence", () => {
735 context: { terminalFocus: true },743 context: { terminalFocus: true },
736 }),744 }),
737 );745 );
738 assert.isTrue(746 assert.strictEqual(
739 isChatNewShortcut(event({ key: "n", ctrlKey: true }), keybindings, {747 resolveShortcutCommand(event({ key: "n", ctrlKey: true }), keybindings, {
740 platform: "Linux",748 platform: "Linux",
741 context: { terminalFocus: true },749 context: { terminalFocus: true },
742 }),750 }),
751 "chat.new",
743 );752 );
744 });753 });
745});754});
apps/web/src/keybindings.ts-24
...@@ -288,14 +288,6 @@ export function threadTraversalDirectionFromCommand(...@@ -288,14 +288,6 @@ export function threadTraversalDirectionFromCommand(
288 return null;288 return null;
289}289}
290290
291export function shouldShowThreadJumpHints(
292 event: ShortcutEventLike,
293 keybindings: ResolvedKeybindingsConfig,
294 options?: ShortcutMatchOptions,
295): boolean {
296 return shouldShowThreadJumpHintsForModifiers(event, keybindings, options);
297}
298
299export function shouldShowThreadJumpHintsForModifiers(291export function shouldShowThreadJumpHintsForModifiers(
300 modifiers: ShortcutModifierStateLike,292 modifiers: ShortcutModifierStateLike,
301 keybindings: ResolvedKeybindingsConfig,293 keybindings: ResolvedKeybindingsConfig,
...@@ -419,22 +411,6 @@ export function isPreviewRefreshShortcut(...@@ -419,22 +411,6 @@ export function isPreviewRefreshShortcut(
419 return matchesCommandShortcut(event, keybindings, "preview.refresh", options);411 return matchesCommandShortcut(event, keybindings, "preview.refresh", options);
420}412}
421413
422export function isChatNewShortcut(
423 event: ShortcutEventLike,
424 keybindings: ResolvedKeybindingsConfig,
425 options?: ShortcutMatchOptions,
426): boolean {
427 return matchesCommandShortcut(event, keybindings, "chat.new", options);
428}
429
430export function isChatNewLocalShortcut(
431 event: ShortcutEventLike,
432 keybindings: ResolvedKeybindingsConfig,
433 options?: ShortcutMatchOptions,
434): boolean {
435 return matchesCommandShortcut(event, keybindings, "chat.newLocal", options);
436}
437
438export function isOpenFavoriteEditorShortcut(414export function isOpenFavoriteEditorShortcut(
439 event: ShortcutEventLike,415 event: ShortcutEventLike,
440 keybindings: ResolvedKeybindingsConfig,416 keybindings: ResolvedKeybindingsConfig,