Skip to content

Commit b150867

Browse files
authored
feat(web): assign a thread details panel shortcut (pingdotgg#16694)
Co-authored-by: maria-rcks <[email protected]>
1 parent 22ccf8a commit b150867

4 files changed

Lines changed: 62 additions & 13 deletions

File tree

‎apps/server/src/keybindings.test.ts‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,16 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
258258
yield* writeKeybindingsConfig(keybindingsConfigPath, [
259259
{ key: "mod+shift+y", command: "terminal.toggle" },
260260
{ key: "mod+shift+r", command: "script.run-tests.run" },
261+
{ key: "mod+shift+b", command: "script.custom-panel.run" },
262+
{
263+
key: "mod+shift+b",
264+
command: "script.custom-composer.run",
265+
when: "composerFocus",
266+
},
261267
]);
262268

263-
yield* Effect.gen(function* () {
264-
const keybindings = yield* Keybindings.Keybindings;
265-
yield* keybindings.syncDefaultKeybindingsOnStartup;
266-
});
269+
const keybindings = yield* Keybindings.Keybindings;
270+
yield* keybindings.syncDefaultKeybindingsOnStartup;
267271

268272
const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
269273
const byCommand = new Map(persisted.map((entry) => [entry.command, entry]));
@@ -279,6 +283,14 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
279283
assert.isTrue(byCommand.has(defaultRule.command), `expected ${defaultRule.command}`);
280284
}
281285
assert.isTrue(byCommand.has("script.run-tests.run"));
286+
287+
const configState = yield* keybindings.loadConfigState;
288+
assert.deepEqual(
289+
configState.keybindings
290+
.filter((entry) => entry.shortcut.key === "b" && entry.shortcut.shiftKey)
291+
.map((entry) => entry.command),
292+
["threadPanel.toggle", "script.custom-panel.run", "script.custom-composer.run"],
293+
);
282294
}).pipe(Effect.provide(layerKeybindings())),
283295
);
284296

@@ -295,8 +307,8 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
295307

296308
yield* keybindings.syncDefaultKeybindingsOnStartup;
297309
assert.deepStrictEqual(yield* backgroundRules, [
298-
existing,
299310
{ key: "mod+enter", command: "composer.sendBackground", when },
311+
existing,
300312
]);
301313

302314
// Removing the added rule later must survive the next startup.

‎apps/server/src/keybindings.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ const make = Effect.gen(function* () {
592592
}
593593
}
594594

595-
// Startup backfill must never evict persisted user rules: append only
596-
// the defaults that fit and skip the rest.
595+
// Keep only defaults that fit, before persisted rules so existing
596+
// custom shortcuts retain priority when their conditions overlap.
597597
const availableSlots = Math.max(0, MAX_KEYBINDINGS_COUNT - customConfig.length);
598598
const defaultsToAppend = missingDefaults.slice(0, availableSlots);
599599
const skippedDefaults = missingDefaults.slice(availableSlots);
@@ -605,7 +605,7 @@ const make = Effect.gen(function* () {
605605
});
606606
}
607607
if (defaultsToAppend.length > 0) {
608-
yield* writeConfigAtomically([...customConfig, ...defaultsToAppend]);
608+
yield* writeConfigAtomically([...defaultsToAppend, ...customConfig]);
609609
}
610610
// A late default skipped at max entries stays pending for a later start.
611611
const settledLateDefaults = pendingLateDefaults.filter(

‎apps/web/src/keybindings.test.ts‎

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,16 +748,52 @@ describe("chat/editor shortcuts", () => {
748748
);
749749
});
750750

751-
it("resolves a user-configured thread panel shortcut without assigning a default", () => {
752-
const bindings = compile([
753-
{ shortcut: modShortcut("b", { shiftKey: true }), command: "threadPanel.toggle" },
754-
]);
751+
it("toggles the thread panel by default without taking terminal keystrokes", () => {
752+
for (const platform of ["MacIntel", "Win32", "Linux"]) {
753+
const input = event({
754+
key: "b",
755+
metaKey: platform === "MacIntel",
756+
ctrlKey: platform !== "MacIntel",
757+
shiftKey: true,
758+
});
759+
assert.strictEqual(
760+
resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
761+
platform,
762+
context: { terminalFocus: false, editableFocus: true },
763+
}),
764+
"threadPanel.toggle",
765+
);
766+
assert.isNull(
767+
resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
768+
platform,
769+
context: { terminalFocus: true },
770+
}),
771+
);
772+
}
773+
});
774+
775+
it("preserves a user-configured thread panel shortcut instead of its default", () => {
776+
const bindings = mergeWithDefaultKeybindings(
777+
compile([
778+
{
779+
shortcut: modShortcut("b", { altKey: true, shiftKey: true }),
780+
command: "threadPanel.toggle",
781+
},
782+
]),
783+
);
755784

756785
assert.strictEqual(
786+
resolveShortcutCommand(
787+
event({ key: "b", metaKey: true, altKey: true, shiftKey: true }),
788+
bindings,
789+
{ platform: "MacIntel" },
790+
),
791+
"threadPanel.toggle",
792+
);
793+
assert.isNull(
757794
resolveShortcutCommand(event({ key: "b", metaKey: true, shiftKey: true }), bindings, {
758795
platform: "MacIntel",
759796
}),
760-
"threadPanel.toggle",
761797
);
762798
});
763799

‎packages/shared/src/keybindings.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
126126
{ key: "mod+]", command: "navigation.forward", when: "!terminalFocus" },
127127
{ key: "mod+j", command: "terminal.toggle" },
128128
{ key: "mod+alt+b", command: "rightPanel.toggle" },
129+
{ key: "mod+shift+b", command: "threadPanel.toggle", when: "!terminalFocus" },
129130
{ key: "mod+t", command: "rightPanel.new", when: "rightPanelOpen && !terminalFocus" },
130131
{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },
131132
{ key: "mod+shift+d", command: "terminal.splitVertical", when: "terminalFocus" },

0 commit comments

Comments
 (0)