History

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

Julius Marminge committed 2 months ago

Commit 009c13f1 parent ee150e12 files · +33 −48Browse files

Unified · Split

2 files
  1. apps/web/src/keybindings.test.ts +33 −24
  2. apps/web/src/keybindings.ts +0 −24
apps/web/src/keybindings.test.ts+33−24
@@ -8,8 +8,6 @@ import { · 7 unmodified lines
88 } from "@t3tools/contracts";
99 import {
1010 formatShortcutLabel,
11− isChatNewShortcut,
12− isChatNewLocalShortcut,
1311 isDiffToggleShortcut,
1412 modelPickerJumpCommandForIndex,
1513 modelPickerJumpIndexFromCommand,
@@ -22,7 +20,7 @@ import { · 6 unmodified lines
2220 isTerminalToggleShortcut,
2321 resolveShortcutCommand,
2422 shouldShowModelPickerJumpHints,
25− shouldShowThreadJumpHints,
23+ shouldShowThreadJumpHintsForModifiers,
2624 shortcutLabelForCommand,
2725 terminalDeleteShortcutData,
2826 terminalNavigationShortcutData,
@@ -498,17 +496,21 @@ describe("thread navigation helpers", () => { · 469 unmodified lines
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", () => { · 1 unmodified line
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", () => { · 29 unmodified lines
558560
559561 describe("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", () => { · 113 unmodified lines
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", () => { · 1 unmodified line
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", () => { · 13 unmodified lines
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+0−24
@@ -288,14 +288,6 @@ export function threadTraversalDirectionFromCommand( · 287 unmodified lines
288288 return null;
289289 }
290290
291−export function shouldShowThreadJumpHints(
292− event: ShortcutEventLike,
293− keybindings: ResolvedKeybindingsConfig,
294− options?: ShortcutMatchOptions,
295−): boolean {
296− return shouldShowThreadJumpHintsForModifiers(event, keybindings, options);
297−}
298−
299291 export function shouldShowThreadJumpHintsForModifiers(
300292 modifiers: ShortcutModifierStateLike,
301293 keybindings: ResolvedKeybindingsConfig,
@@ -419,22 +411,6 @@ export function isPreviewRefreshShortcut( · 117 unmodified lines
419411 return matchesCommandShortcut(event, keybindings, "preview.refresh", options);
420412 }
421413
422−export function isChatNewShortcut(
423− event: ShortcutEventLike,
424− keybindings: ResolvedKeybindingsConfig,
425− options?: ShortcutMatchOptions,
426−): boolean {
427− return matchesCommandShortcut(event, keybindings, "chat.new", options);
428−}
429−
430−export function isChatNewLocalShortcut(
431− event: ShortcutEventLike,
432− keybindings: ResolvedKeybindingsConfig,
433− options?: ShortcutMatchOptions,
434−): boolean {
435− return matchesCommandShortcut(event, keybindings, "chat.newLocal", options);
436−}
437−
438414 export function isOpenFavoriteEditorShortcut(
439415 event: ShortcutEventLike,
440416 keybindings: ResolvedKeybindingsConfig,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t