The best way to control Claude Code, Codex and more from any computer or phone
fix(server): editing or removing a hand-written shortcut in Settings works again (#25556)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
MarcoDotIO committed
Oct 30, 2026 at 17:16 UTC
286bc5eb1e2e772bfa7817fff37562f5f4c2e768
2 files changed
+67
-5
apps/server/src/keybindings.test.ts
+55
@@ -444,6 +444,61 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
444
}).pipe(Effect.provide(layerKeybindings())),
445
);
446
447
+ it.effect("removes a hand-written keybinding targeted by its settings spelling", () =>
448
+ Effect.gen(function* () {
449
+ const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
450
+ yield* writeKeybindingsConfig(keybindingsConfigPath, [
451
+ {
452
+ key: "Shift+Cmd+R",
453
+ command: "script.run-tests.run",
454
+ when: "terminalFocus&&!previewFocus",
455
+ },
456
+ { key: "mod+shift+r", command: "script.run-tests.run" },
457
+ { key: "x\u0000true", command: "script.run-tests.run" },
458
+ { key: "x", command: "script.run-tests.run", when: "true" },
459
+ ]);
460
+ yield* Effect.gen(function* () {
461
+ const keybindings = yield* Keybindings.Keybindings;
462
+ yield* keybindings.removeKeybindingRule({
463
+ key: "meta+shift+r",
464
+ command: "script.run-tests.run",
465
+ when: "terminalFocus && !previewFocus",
466
+ });
467
+ yield* keybindings.removeKeybindingRule({
468
+ key: "x",
469
+ command: "script.run-tests.run",
470
+ when: "true",
471
+ });
472
+ });
473
+
474
+ const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
475
+ assert.deepEqual(persisted, [
476
+ { key: "mod+shift+r", command: "script.run-tests.run" },
477
+ { key: "x\u0000true", command: "script.run-tests.run" },
478
+ ]);
479
+ }).pipe(Effect.provide(layerKeybindings())),
480
+ );
481
+
482
+ it.effect("replaces a hand-written keybinding targeted by its settings spelling", () =>
483
+ Effect.gen(function* () {
484
+ const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
485
+ yield* writeKeybindingsConfig(keybindingsConfigPath, [
486
+ { key: "escape", command: "script.run-tests.run", when: "a && b && c" },
487
+ ]);
488
+ yield* Effect.gen(function* () {
489
+ const keybindings = yield* Keybindings.Keybindings;
490
+ return yield* keybindings.upsertKeybindingRule({
491
+ key: "mod+alt+r",
492
+ command: "script.run-tests.run",
493
+ replace: { key: "esc", command: "script.run-tests.run", when: "(a && b) && c" },
494
+ });
495
+ });
496
+
497
+ const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
498
+ assert.deepEqual(persisted, [{ key: "mod+alt+r", command: "script.run-tests.run" }]);
499
+ }).pipe(Effect.provide(layerKeybindings())),
500
+ );
501
+
502
it.effect("refuses to overwrite malformed keybindings config", () =>
503
Effect.gen(function* () {
504
const fs = yield* FileSystem.FileSystem;
apps/server/src/keybindings.ts
+12
-5
@@ -41,6 +41,7 @@ import {
41
compileResolvedKeybindingRule,
42
compileResolvedKeybindingsConfig,
43
parseKeybindingShortcut,
44
+ parseKeybindingWhenExpression,
45
} from "@t3tools/shared/keybindings";
46
47
export const ResolvedKeybindingFromConfig = KeybindingRule.pipe(
@@ -80,12 +81,18 @@ export const ResolvedKeybindingFromConfig = KeybindingRule.pipe(
81
),
82
);
83
84
+// Settings sends replace/remove targets in its own normalized spelling, which can differ from a
85
+// hand-edited file ("cmd+k" vs "meta+k", "a&&b" vs "a && b"), so compare parsed forms.
86
+function keybindingRuleIdentity(rule: KeybindingRule): string {
87
+ const shortcut = parseKeybindingShortcut(rule.key);
88
+ const key = (shortcut && encodeShortcut(shortcut)) ?? rule.key;
89
+ if (rule.when === undefined) return JSON.stringify([rule.command, key, null]);
90
+ const whenAst = parseKeybindingWhenExpression(rule.when);
91
+ return JSON.stringify([rule.command, key, whenAst ? encodeWhenAst(whenAst) : rule.when]);
92
+}
93
+
94
function isSameKeybindingRule(left: KeybindingRule, right: KeybindingRule): boolean {
84
- return (
85
- left.command === right.command &&
86
- left.key === right.key &&
87
- (left.when ?? undefined) === (right.when ?? undefined)
88
- );
95
+ return keybindingRuleIdentity(left) === keybindingRuleIdentity(right);
96
}
97
98
const LATE_DEFAULT_KEYBINDINGS: ReadonlyArray<{