Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion desktop/src/features/terminal/TerminalSubstrate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,17 @@ export function TerminalSubstrate({
<span>{shortcutLabel} BUZZ</span>
</div>
</div>
<div className="buzz-terminal-viewport">
{/* biome-ignore lint/a11y/noStaticElementInteractions: the hidden textarea owns keyboard semantics; this only preserves its focus across canvas clicks. */}
<div
className="buzz-terminal-viewport"
onMouseDown={(event) => {
if (owner !== "terminal") return;
// Preventing the canvas mousedown also suppresses selection. Revisit
// this when the terminal gains mouse selection support.
event.preventDefault();
textareaRef.current?.focus({ preventScroll: true });
}}
>
<canvas ref={canvasRef} />
{welcomeVisible && banner ? (
<canvas className="buzz-terminal-welcome" ref={bannerCanvasRef} />
Expand Down
43 changes: 43 additions & 0 deletions desktop/tests/e2e/terminal-wheel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,46 @@ test("scrollback: wheel over Buzz Term reaches terminal_scroll", async ({
console.log("SCROLLS", JSON.stringify(scrolls));
expect(scrolls).toEqual([-5, 2]);
});

test("terminal viewport click retains keyboard input ownership", async ({
page,
}) => {
await reveal(page);
const input = page.getByLabel("Terminal input");
await expect(input).toBeFocused();

await page
.locator(".buzz-terminal-viewport")
.click({ position: { x: 40, y: 40 } });
await expect(input).toBeFocused();

await page.keyboard.type("FOCUS_KEYSTROKE");
await expect
.poll(async () =>
page.evaluate(() =>
(
window as typeof window & { __SAMI_TERM__: { inputs: string[] } }
).__SAMI_TERM__.inputs.join(""),
),
)
.toContain("FOCUS_KEYSTROKE");
});

test("concealed terminal viewport does not steal Buzz focus", async ({
page,
}) => {
await reveal(page);
await page.keyboard.press("Meta+j");
await expect(page.locator(TERM)).toHaveAttribute(
"data-terminal-owner",
"buzz",
);

const input = page.getByLabel("Terminal input");
await expect(input).not.toBeFocused();
await page.locator(".buzz-terminal-viewport").click({
force: true,
position: { x: 40, y: 40 },
});
await expect(input).not.toBeFocused();
});
Loading