TypeScript
refactor(web): test live keybinding resolvers directly (#10069)
Julius Marminge009c13fade9d
diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.tsindex 8cbc4596652..6390269ea0d 100644--- a/apps/web/src/keybindings.test.ts+++ b/apps/web/src/keybindings.test.ts@@ -8,8 +8,6 @@ import {} from "@t3tools/contracts";import {formatShortcutLabel,- isChatNewShortcut,- isChatNewLocalShortcut,isDiffToggleShortcut,modelPickerJumpCommandForIndex,modelPickerJumpIndexFromCommand,@@ -22,7 +20,7 @@ import {isTerminalToggleShortcut,resolveShortcutCommand,shouldShowModelPickerJumpHints,- shouldShowThreadJumpHints,+ shouldShowThreadJumpHintsForModifiers,shortcutLabelForCommand,terminalDeleteShortcutData,terminalNavigationShortcutData,@@ -498,17 +496,21 @@ describe("thread navigation helpers", () => {it("shows jump hints only when configured modifiers match", () => {assert.isTrue(- shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {+ shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {platform: "MacIntel",}),);assert.isFalse(- shouldShowThreadJumpHints(event({ metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {- platform: "MacIntel",- }),+ shouldShowThreadJumpHintsForModifiers(+ event({ metaKey: true, shiftKey: true }),+ DEFAULT_BINDINGS,+ {+ platform: "MacIntel",+ },+ ),);assert.isTrue(- shouldShowThreadJumpHints(event({ ctrlKey: true }), DEFAULT_BINDINGS, {+ shouldShowThreadJumpHintsForModifiers(event({ ctrlKey: true }), DEFAULT_BINDINGS, {platform: "Linux",}),);@@ -516,13 +518,13 @@ describe("thread navigation helpers", () => {it("never shows jump hints while the terminal is focused, even with an unrestricted binding", () => {assert.isFalse(- shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {+ shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {platform: "MacIntel",context: { terminalFocus: true },}),);assert.isTrue(- shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {+ shouldShowThreadJumpHintsForModifiers(event({ metaKey: true }), DEFAULT_BINDINGS, {platform: "MacIntel",context: { terminalFocus: false },}),@@ -558,28 +560,32 @@ describe("model picker navigation helpers", () => {describe("chat/editor shortcuts", () => {it("matches chat.new shortcut", () => {- assert.isTrue(- isChatNewShortcut(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {+ assert.strictEqual(+ resolveShortcutCommand(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {platform: "MacIntel",}),+ "chat.new",);- assert.isTrue(- isChatNewShortcut(event({ key: "o", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {+ assert.strictEqual(+ resolveShortcutCommand(event({ key: "o", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {platform: "Linux",}),+ "chat.new",);});it("matches chat.newLocal shortcut", () => {- assert.isTrue(- isChatNewLocalShortcut(event({ key: "n", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {+ assert.strictEqual(+ resolveShortcutCommand(event({ key: "n", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {platform: "MacIntel",}),+ "chat.newLocal",);- assert.isTrue(- isChatNewLocalShortcut(event({ key: "n", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {+ assert.strictEqual(+ resolveShortcutCommand(event({ key: "n", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {platform: "Linux",}),+ "chat.newLocal",);});@@ -699,11 +705,12 @@ describe("cross-command precedence", () => {context: { terminalFocus: true },}),);- assert.isFalse(- isChatNewShortcut(event({ key: "n", metaKey: true }), keybindings, {+ assert.strictEqual(+ resolveShortcutCommand(event({ key: "n", metaKey: true }), keybindings, {platform: "MacIntel",context: { terminalFocus: true },}),+ "terminal.new",);assert.isFalse(isTerminalNewShortcut(event({ key: "n", metaKey: true }), keybindings, {@@ -711,11 +718,12 @@ describe("cross-command precedence", () => {context: { terminalFocus: false },}),);- assert.isTrue(- isChatNewShortcut(event({ key: "n", metaKey: true }), keybindings, {+ assert.strictEqual(+ resolveShortcutCommand(event({ key: "n", metaKey: true }), keybindings, {platform: "MacIntel",context: { terminalFocus: false },}),+ "chat.new",);});@@ -735,11 +743,12 @@ describe("cross-command precedence", () => {context: { terminalFocus: true },}),);- assert.isTrue(- isChatNewShortcut(event({ key: "n", ctrlKey: true }), keybindings, {+ assert.strictEqual(+ resolveShortcutCommand(event({ key: "n", ctrlKey: true }), keybindings, {platform: "Linux",context: { terminalFocus: true },}),+ "chat.new",);});});diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.tsindex 2a8d385cb42..62f107a4daa 100644--- a/apps/web/src/keybindings.ts+++ b/apps/web/src/keybindings.ts@@ -288,14 +288,6 @@ export function threadTraversalDirectionFromCommand(return null;}-export function shouldShowThreadJumpHints(- event: ShortcutEventLike,- keybindings: ResolvedKeybindingsConfig,- options?: ShortcutMatchOptions,-): boolean {- return shouldShowThreadJumpHintsForModifiers(event, keybindings, options);-}-export function shouldShowThreadJumpHintsForModifiers(modifiers: ShortcutModifierStateLike,keybindings: ResolvedKeybindingsConfig,@@ -419,22 +411,6 @@ export function isPreviewRefreshShortcut(return matchesCommandShortcut(event, keybindings, "preview.refresh", options);}-export function isChatNewShortcut(- event: ShortcutEventLike,- keybindings: ResolvedKeybindingsConfig,- options?: ShortcutMatchOptions,-): boolean {- return matchesCommandShortcut(event, keybindings, "chat.new", options);-}--export function isChatNewLocalShortcut(- event: ShortcutEventLike,- keybindings: ResolvedKeybindingsConfig,- options?: ShortcutMatchOptions,-): boolean {- return matchesCommandShortcut(event, keybindings, "chat.newLocal", options);-}-export function isOpenFavoriteEditorShortcut(event: ShortcutEventLike,keybindings: ResolvedKeybindingsConfig,