Skip to content

Commit 02a72c6

Browse files
jakeleventhalclaude
andcommitted
fix(server): don't let a conditional default shadow a user's unconditional shortcut
Startup default sync only treated identical `when` strings as conflicts, so a default like `f8 voice.toggle when !terminalFocus` was appended after a user's bare `f8` binding and won whenever the terminal lacked focus. A default is now skipped when its shortcut matches a user rule and either side is unconditional. Also corrects the voice lifecycle comment: screens pushed over the thread keep a conversation running. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 823d3eb commit 02a72c6

3 files changed

Lines changed: 31 additions & 14 deletions

File tree

‎apps/mobile/src/features/voice-mode/useVoiceMode.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export function useVoiceModePhase(target: VoiceSessionTarget): VoiceModePhase {
2626

2727
/**
2828
* Ties a conversation to the screen showing its thread: leaving the thread
29-
* ends it, so the microphone is never live without its controls on screen.
29+
* ends it. Screens pushed over the thread (files, review, settings) keep it
30+
* running, like a call; its controls return with the thread.
3031
* Also reports failures and remote endings for this thread, once.
3132
*/
3233
export function useVoiceModeThreadLifecycle(target: VoiceSessionTarget): void {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,24 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
396396
);
397397
});
398398

399+
it.effect("skips a conditional default that would shadow an unconditional user shortcut", () =>
400+
Effect.gen(function* () {
401+
const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
402+
yield* writeKeybindingsConfig(keybindingsConfigPath, [
403+
{ key: "f8", command: "script.custom-action.run" },
404+
]);
405+
406+
yield* Effect.gen(function* () {
407+
const keybindings = yield* Keybindings.Keybindings;
408+
yield* keybindings.syncDefaultKeybindingsOnStartup;
409+
});
410+
411+
const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
412+
assert.isFalse(persisted.some((entry) => entry.command === "voice.toggle"));
413+
assert.isTrue(persisted.some((entry) => entry.command === "navigation.back"));
414+
}).pipe(Effect.provide(makeKeybindingsLayer())),
415+
);
416+
399417
it.effect("upserts custom keybindings to configured path", () =>
400418
Effect.gen(function* () {
401419
const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;

‎apps/server/src/keybindings.ts‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ const LATE_DEFAULT_KEYBINDINGS: ReadonlyArray<{
115115
},
116116
];
117117

118-
function keybindingShortcutContext(rule: KeybindingRule): string | null {
118+
function encodedRuleShortcut(rule: KeybindingRule): string | null {
119119
const parsed = parseKeybindingShortcut(rule.key);
120-
if (!parsed) return null;
121-
const encoded = encodeShortcut(parsed);
122-
if (!encoded) return null;
123-
return `${encoded}\u0000${rule.when ?? ""}`;
120+
return parsed ? encodeShortcut(parsed) : null;
124121
}
125122

126-
function hasSameShortcutContext(left: KeybindingRule, right: KeybindingRule): boolean {
127-
const leftContext = keybindingShortcutContext(left);
128-
const rightContext = keybindingShortcutContext(right);
129-
if (!leftContext || !rightContext) return false;
130-
return leftContext === rightContext;
123+
/**
124+
* Whether appending `rule` after `existing` would shadow it: same shortcut, and
125+
* either the same `when` or one of them applies in every context.
126+
*/
127+
function shadowsShortcut(existing: KeybindingRule, rule: KeybindingRule): boolean {
128+
const existingShortcut = encodedRuleShortcut(existing);
129+
if (!existingShortcut || existingShortcut !== encodedRuleShortcut(rule)) return false;
130+
return existing.when === undefined || rule.when === undefined || existing.when === rule.when;
131131
}
132132

133133
function keybindingRuleFromUpsertInput(input: ServerUpsertKeybindingInput): KeybindingRule {
@@ -502,9 +502,7 @@ const make = Effect.gen(function* () {
502502
if (existingCommands.has(defaultRule.command)) {
503503
continue;
504504
}
505-
const conflictingEntry = customConfig.find((entry) =>
506-
hasSameShortcutContext(entry, defaultRule),
507-
);
505+
const conflictingEntry = customConfig.find((entry) => shadowsShortcut(entry, defaultRule));
508506
if (conflictingEntry) {
509507
shortcutConflictWarnings.push({
510508
defaultCommand: defaultRule.command,

0 commit comments

Comments
 (0)