TypeScript
feat(web): assign a thread details panel shortcut (#16694)
mariab1508672a63c
diff --git a/apps/server/src/keybindings.test.ts b/apps/server/src/keybindings.test.tsindex 38b6b3a9c20..f6c3cb9e884 100644--- a/apps/server/src/keybindings.test.ts+++ b/apps/server/src/keybindings.test.ts@@ -258,12 +258,16 @@ it.layer(NodeServices.layer)("keybindings", (it) => {yield* writeKeybindingsConfig(keybindingsConfigPath, [{ key: "mod+shift+y", command: "terminal.toggle" },{ key: "mod+shift+r", command: "script.run-tests.run" },+ { key: "mod+shift+b", command: "script.custom-panel.run" },+ {+ key: "mod+shift+b",+ command: "script.custom-composer.run",+ when: "composerFocus",+ },]);- yield* Effect.gen(function* () {- const keybindings = yield* Keybindings.Keybindings;- yield* keybindings.syncDefaultKeybindingsOnStartup;- });+ const keybindings = yield* Keybindings.Keybindings;+ yield* keybindings.syncDefaultKeybindingsOnStartup;const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);const byCommand = new Map(persisted.map((entry) => [entry.command, entry]));@@ -279,6 +283,14 @@ it.layer(NodeServices.layer)("keybindings", (it) => {assert.isTrue(byCommand.has(defaultRule.command), `expected ${defaultRule.command}`);}assert.isTrue(byCommand.has("script.run-tests.run"));++ const configState = yield* keybindings.loadConfigState;+ assert.deepEqual(+ configState.keybindings+ .filter((entry) => entry.shortcut.key === "b" && entry.shortcut.shiftKey)+ .map((entry) => entry.command),+ ["threadPanel.toggle", "script.custom-panel.run", "script.custom-composer.run"],+ );}).pipe(Effect.provide(layerKeybindings())),);@@ -295,8 +307,8 @@ it.layer(NodeServices.layer)("keybindings", (it) => {yield* keybindings.syncDefaultKeybindingsOnStartup;assert.deepStrictEqual(yield* backgroundRules, [- existing,{ key: "mod+enter", command: "composer.sendBackground", when },+ existing,]);// Removing the added rule later must survive the next startup.diff --git a/apps/server/src/keybindings.ts b/apps/server/src/keybindings.tsindex 332aa7134bd..496a5852979 100644--- a/apps/server/src/keybindings.ts+++ b/apps/server/src/keybindings.ts@@ -592,8 +592,8 @@ const make = Effect.gen(function* () {}}- // Startup backfill must never evict persisted user rules: append only- // the defaults that fit and skip the rest.+ // Keep only defaults that fit, before persisted rules so existing+ // custom shortcuts retain priority when their conditions overlap.const availableSlots = Math.max(0, MAX_KEYBINDINGS_COUNT - customConfig.length);const defaultsToAppend = missingDefaults.slice(0, availableSlots);const skippedDefaults = missingDefaults.slice(availableSlots);@@ -605,7 +605,7 @@ const make = Effect.gen(function* () {});}if (defaultsToAppend.length > 0) {- yield* writeConfigAtomically([...customConfig, ...defaultsToAppend]);+ yield* writeConfigAtomically([...defaultsToAppend, ...customConfig]);}// A late default skipped at max entries stays pending for a later start.const settledLateDefaults = pendingLateDefaults.filter(diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.tsindex 73b1fa8fc00..d1e842205ef 100644--- a/apps/web/src/keybindings.test.ts+++ b/apps/web/src/keybindings.test.ts@@ -748,16 +748,52 @@ describe("chat/editor shortcuts", () => {);});- it("resolves a user-configured thread panel shortcut without assigning a default", () => {- const bindings = compile([- { shortcut: modShortcut("b", { shiftKey: true }), command: "threadPanel.toggle" },- ]);+ it("toggles the thread panel by default without taking terminal keystrokes", () => {+ for (const platform of ["MacIntel", "Win32", "Linux"]) {+ const input = event({+ key: "b",+ metaKey: platform === "MacIntel",+ ctrlKey: platform !== "MacIntel",+ shiftKey: true,+ });+ assert.strictEqual(+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {+ platform,+ context: { terminalFocus: false, editableFocus: true },+ }),+ "threadPanel.toggle",+ );+ assert.isNull(+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {+ platform,+ context: { terminalFocus: true },+ }),+ );+ }+ });++ it("preserves a user-configured thread panel shortcut instead of its default", () => {+ const bindings = mergeWithDefaultKeybindings(+ compile([+ {+ shortcut: modShortcut("b", { altKey: true, shiftKey: true }),+ command: "threadPanel.toggle",+ },+ ]),+ );assert.strictEqual(+ resolveShortcutCommand(+ event({ key: "b", metaKey: true, altKey: true, shiftKey: true }),+ bindings,+ { platform: "MacIntel" },+ ),+ "threadPanel.toggle",+ );+ assert.isNull(resolveShortcutCommand(event({ key: "b", metaKey: true, shiftKey: true }), bindings, {platform: "MacIntel",}),- "threadPanel.toggle",);});diff --git a/packages/shared/src/keybindings.ts b/packages/shared/src/keybindings.tsindex 0e95775fbb3..7620b2432a7 100644--- a/packages/shared/src/keybindings.ts+++ b/packages/shared/src/keybindings.ts@@ -126,6 +126,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [{ key: "mod+]", command: "navigation.forward", when: "!terminalFocus" },{ key: "mod+j", command: "terminal.toggle" },{ key: "mod+alt+b", command: "rightPanel.toggle" },+ { key: "mod+shift+b", command: "threadPanel.toggle", when: "!terminalFocus" },{ key: "mod+t", command: "rightPanel.new", when: "rightPanelOpen && !terminalFocus" },{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },{ key: "mod+shift+d", command: "terminal.splitVertical", when: "terminalFocus" },