From 050cfc89e3c4a54583222736a7049e91cb9cd984 Mon Sep 17 00:00:00 2001 From: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@buzz.block.builderlab.xyz> Date: Sun, 2 Aug 2026 21:39:12 -0400 Subject: [PATCH 1/3] fix(desktop): retain terminal focus after tab actions Co-authored-by: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@buzz.block.builderlab.xyz> Signed-off-by: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@buzz.block.builderlab.xyz> --- .../terminal/TerminalSubstrate.test.mjs | 24 +++++++++++++++++++ .../features/terminal/TerminalSubstrate.tsx | 13 +++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/desktop/src/features/terminal/TerminalSubstrate.test.mjs b/desktop/src/features/terminal/TerminalSubstrate.test.mjs index 4759d2b35..9c5047e14 100644 --- a/desktop/src/features/terminal/TerminalSubstrate.test.mjs +++ b/desktop/src/features/terminal/TerminalSubstrate.test.mjs @@ -159,6 +159,30 @@ test("mounted IME paths neither toggle nor emit preedit text", async () => { assert.deepEqual(calls.input, ["か"]); }); +test("tab actions restore terminal input focus", async () => { + const { view } = fixture(); + await ready(view); + toggleChord(); + const input = view.getByLabelText("Terminal input"); + await waitFor(() => assert.equal(document.activeElement, input)); + + const actions = [ + ["select", view.getByRole("tab")], + ["close", view.getByLabelText("Close SHELL")], + ["new", view.getByLabelText("New Buzz Term tab")], + ]; + for (const [label, target] of actions) { + target.focus(); + assert.equal(document.activeElement, target, `${label} takes focus`); + fireEvent.click(target); + assert.equal( + document.activeElement, + input, + `${label} restores terminal focus`, + ); + } +}); + const EMPTY_FRAME = { cursor: { column: 0, line: 0, visible: false }, full: false, diff --git a/desktop/src/features/terminal/TerminalSubstrate.tsx b/desktop/src/features/terminal/TerminalSubstrate.tsx index 4b069af9b..87c933c25 100644 --- a/desktop/src/features/terminal/TerminalSubstrate.tsx +++ b/desktop/src/features/terminal/TerminalSubstrate.tsx @@ -391,6 +391,13 @@ export function TerminalSubstrate({ gridRef.current?.paint(context, TERMINAL_CELL_METRICS, terminalPalette); }, [activeSessionId, cursorPainted, frames, terminalPalette]); + const runTabAction = (action: () => void) => { + action(); + if (owner === "terminal") { + textareaRef.current?.focus({ preventScroll: true }); + } + }; + return (
onSelectSession(session.id)} + onClick={() => runTabAction(() => onSelectSession(session.id))} role="tab" type="button" > @@ -444,7 +451,7 @@ export function TerminalSubstrate({ aria-label={`Close ${session.title}`} className="buzz-terminal-close" disabled={session.closing} - onClick={() => onCloseSession(session.id)} + onClick={() => runTabAction(() => onCloseSession(session.id))} type="button" > × @@ -454,7 +461,7 @@ export function TerminalSubstrate({