Skip to content

Commit 751d615

Browse files
t3dotggclaude
andcommitted
fix(server): add mod+enter only next to the untouched mod+alt+enter default
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent dbec31e commit 751d615

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,26 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
307307
}).pipe(Effect.provide(makeKeybindingsLayer())),
308308
);
309309

310+
it.effect("leaves a customized command without the late default", () =>
311+
Effect.gen(function* () {
312+
const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
313+
const keybindings = yield* Keybindings.Keybindings;
314+
const custom = {
315+
key: "alt+b",
316+
command: "composer.sendBackground",
317+
when: "composerFocus && draftThreadRoute",
318+
} as const;
319+
yield* writeKeybindingsConfig(keybindingsConfigPath, [custom]);
320+
321+
yield* keybindings.syncDefaultKeybindingsOnStartup;
322+
const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
323+
assert.deepStrictEqual(
324+
persisted.filter((entry) => entry.command === "composer.sendBackground"),
325+
[custom],
326+
);
327+
}).pipe(Effect.provide(makeKeybindingsLayer())),
328+
);
329+
310330
it.effect("keeps a late default pending while the config is full", () =>
311331
Effect.gen(function* () {
312332
const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;

‎apps/server/src/keybindings.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,22 @@ function isSameKeybindingRule(left: KeybindingRule, right: KeybindingRule): bool
105105
}
106106

107107
// Default rules added to a command after startup sync had already persisted
108-
// that command. Backfill skips commands a config already has, so startup
109-
// appends each rule here once per config and records its id. A user who later
110-
// removes the rule keeps it removed.
108+
// that command. Backfill skips commands a config already has, so startup adds
109+
// each rule once per config, only next to the untouched earlier default
110+
// (`alongside`), and records its id. Customized commands and later removals
111+
// stay as the user set them.
111112
const LATE_DEFAULT_KEYBINDINGS: ReadonlyArray<{
112113
readonly id: string;
114+
readonly alongside: KeybindingRule;
113115
readonly rule: KeybindingRule;
114116
}> = [
115117
{
116118
id: "composer.sendBackground:mod+enter",
119+
alongside: {
120+
key: "mod+alt+enter",
121+
command: "composer.sendBackground",
122+
when: "composerFocus && draftThreadRoute",
123+
},
117124
rule: {
118125
key: "mod+enter",
119126
command: "composer.sendBackground",
@@ -551,10 +558,10 @@ const make = Effect.gen(function* () {
551558
missingDefaults.push(defaultRule);
552559
}
553560
// The loop above backfills whole missing commands. Late defaults join
554-
// commands the config already has, when their shortcut is still free.
555-
for (const { rule } of pendingLateDefaults) {
561+
// an untouched earlier default, when their shortcut is still free.
562+
for (const { alongside, rule } of pendingLateDefaults) {
556563
if (
557-
existingCommands.has(rule.command) &&
564+
customConfig.some((entry) => isSameKeybindingRule(entry, alongside)) &&
558565
!customConfig.some((entry) => hasSameShortcutContext(entry, rule))
559566
) {
560567
missingDefaults.push(rule);

0 commit comments

Comments
 (0)