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 {
88} from "@t3tools/contracts";
99import {
1010 formatShortcutLabel,
11 isChatNewShortcut,
12 isChatNewLocalShortcut,
1311 isDiffToggleShortcut,
1412 modelPickerJumpCommandForIndex,
1513 modelPickerJumpIndexFromCommand,
......@@ -22,7 +20,7 @@ import {
2220 isTerminalToggleShortcut,
2321 resolveShortcutCommand,
2422 shouldShowModelPickerJumpHints,
25 shouldShowThreadJumpHints,
23 shouldShowThreadJumpHintsForModifiers,
2624 shortcutLabelForCommand,
2725 terminalDeleteShortcutData,
2826 terminalNavigationShortcutData,
......@@ -498,17 +496,21 @@ describe("thread navigation helpers", () => {
498496
499497 it("shows jump hints only when configured modifiers match", () => {
500498 assert.isTrue(
501 shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
499 shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {
502500 platform: "MacIntel",
503501 }),
504502 );
505503 assert.isFalse(
506 shouldShowThreadJumpHints(event({ metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
507 platform: "MacIntel",
508 }),
504 shouldShowThreadJumpHintsForModifiers(
505 event({ metaKey: true, shiftKey: true }),
506 DEFAULT_BINDINGS,
507 {
508 platform: "MacIntel",
509 },
510 ),
509511 );
510512 assert.isTrue(
511 shouldShowThreadJumpHints(event({ ctrlKey: true }), DEFAULT_BINDINGS, {
513 shouldShowThreadJumpHintsForModifiers(event({ ctrlKey: true }), DEFAULT_BINDINGS, {
512514 platform: "Linux",
513515 }),
514516 );
......@@ -516,13 +518,13 @@ describe("thread navigation helpers", () => {
516518
517519 it("never shows jump hints while the terminal is focused, even with an unrestricted binding", () => {
518520 assert.isFalse(
519 shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
521 shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {
520522 platform: "MacIntel",
521523 context: { terminalFocus: true },
522524 }),
523525 );
524526 assert.isTrue(
525 shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
527 shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {
526528 platform: "MacIntel",
527529 context: { terminalFocus: false },
528530 }),
......@@ -558,28 +560,32 @@ describe("model picker navigation helpers", () => {
558560
559561describe("chat/editor shortcuts", () => {
560562 it("matches chat.new shortcut", () => {
561 assert.isTrue(
562 isChatNewShortcut(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
563 assert.strictEqual(
564 resolveShortcutCommand(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
563565 platform: "MacIntel",
564566 }),
567 "chat.new",
565568 );
566 assert.isTrue(
567 isChatNewShortcut(event({ key: "o", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
569 assert.strictEqual(
570 resolveShortcutCommand(event({ key: "o", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
568571 platform: "Linux",
569572 }),
573 "chat.new",
570574 );
571575 });
572576
573577 it("matches chat.newLocal shortcut", () => {
574 assert.isTrue(
575 isChatNewLocalShortcut(event({ key: "n", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
578 assert.strictEqual(
579 resolveShortcutCommand(event({ key: "n", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
576580 platform: "MacIntel",
577581 }),
582 "chat.newLocal",
578583 );
579 assert.isTrue(
580 isChatNewLocalShortcut(event({ key: "n", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
584 assert.strictEqual(
585 resolveShortcutCommand(event({ key: "n", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
581586 platform: "Linux",
582587 }),
588 "chat.newLocal",
583589 );
584590 });
585591
......@@ -699,11 +705,12 @@ describe("cross-command precedence", () => {
699705 context: { terminalFocus: true },
700706 }),
701707 );
702 assert.isFalse(
703 isChatNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
708 assert.strictEqual(
709 resolveShortcutCommand(event({ key: "n", metaKey: true }), keybindings, {
704710 platform: "MacIntel",
705711 context: { terminalFocus: true },
706712 }),
713 "terminal.new",
707714 );
708715 assert.isFalse(
709716 isTerminalNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
......@@ -711,11 +718,12 @@ describe("cross-command precedence", () => {
711718 context: { terminalFocus: false },
712719 }),
713720 );
714 assert.isTrue(
715 isChatNewShortcut(event({ key: "n", metaKey: true }), keybindings, {
721 assert.strictEqual(
722 resolveShortcutCommand(event({ key: "n", metaKey: true }), keybindings, {
716723 platform: "MacIntel",
717724 context: { terminalFocus: false },
718725 }),
726 "chat.new",
719727 );
720728 });
721729
......@@ -735,11 +743,12 @@ describe("cross-command precedence", () => {
735743 context: { terminalFocus: true },
736744 }),
737745 );
738 assert.isTrue(
739 isChatNewShortcut(event({ key: "n", ctrlKey: true }), keybindings, {
746 assert.strictEqual(
747 resolveShortcutCommand(event({ key: "n", ctrlKey: true }), keybindings, {
740748 platform: "Linux",
741749 context: { terminalFocus: true },
742750 }),
751 "chat.new",
743752 );
744753 });
745754});
apps/web/src/keybindings.ts-24
......@@ -288,14 +288,6 @@ export function threadTraversalDirectionFromCommand(
288288 return null;
289289}
290290
291export function shouldShowThreadJumpHints(
292 event: ShortcutEventLike,
293 keybindings: ResolvedKeybindingsConfig,
294 options?: ShortcutMatchOptions,
295): boolean {
296 return shouldShowThreadJumpHintsForModifiers(event, keybindings, options);
297}
298
299291export function shouldShowThreadJumpHintsForModifiers(
300292 modifiers: ShortcutModifierStateLike,
301293 keybindings: ResolvedKeybindingsConfig,
......@@ -419,22 +411,6 @@ export function isPreviewRefreshShortcut(
419411 return matchesCommandShortcut(event, keybindings, "preview.refresh", options);
420412}
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
438414export function isOpenFavoriteEditorShortcut(
439415 event: ShortcutEventLike,
440416 keybindings: ResolvedKeybindingsConfig,