Skip to content

Commit 211a812

Browse files
committed
fix(web): keep hotkey overlay honest while terminal is focused
The sidebar's thread-jump hint overlay showed configured shortcuts while the embedded terminal was focused, but pressing one just typed the key into the shell: xterm.js consumes the keystroke before our window-level shortcut handling runs, regardless of any `when` clause on the binding. Suppress the overlay whenever the terminal has focus so it never advertises a shortcut that won't actually fire there.
1 parent 949feb6 commit 211a812

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,21 @@ describe("thread navigation helpers", () => {
451451
}),
452452
);
453453
});
454+
455+
it("never shows jump hints while the terminal is focused, even with an unrestricted binding", () => {
456+
assert.isFalse(
457+
shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
458+
platform: "MacIntel",
459+
context: { terminalFocus: true },
460+
}),
461+
);
462+
assert.isTrue(
463+
shouldShowThreadJumpHints(event({ metaKey: true }), DEFAULT_BINDINGS, {
464+
platform: "MacIntel",
465+
context: { terminalFocus: false },
466+
}),
467+
);
468+
});
454469
});
455470

456471
describe("model picker navigation helpers", () => {

‎apps/web/src/keybindings.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ export function shouldShowThreadJumpHintsForModifiers(
301301
keybindings: ResolvedKeybindingsConfig,
302302
options?: ShortcutMatchOptions,
303303
): boolean {
304+
// The embedded terminal owns keystrokes while it has focus: xterm.js
305+
// consumes the keydown and can write the pressed key into the shell
306+
// before our window-level shortcut handling ever runs, regardless of any
307+
// configured `when` clause on the jump command. Advertising jump hints
308+
// here would promise a shortcut that instead types into the terminal, so
309+
// never show them while the terminal is focused.
310+
if (resolveContext(options).terminalFocus) {
311+
return false;
312+
}
313+
304314
const platform = resolvePlatform(options);
305315

306316
for (const command of THREAD_JUMP_KEYBINDING_COMMANDS) {

0 commit comments

Comments
 (0)