From 27c126d352c4544c6a8f43251527d61228b8d12f Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:54:24 +0000 Subject: [PATCH] Keep the Android browser keyboard closed when you swipe a terminal (#10225) * fix(terminal): restore mobile scrolling and touch keyboard focus * fix(app): keep a touch drag from refocusing the browser terminal Builds on the contributor commit for the Android browser keyboard. A touch drag now keeps the dismissed keyboard closed, and a tap still opens it. - Keep calling onFocus on every pointer-down, so a touch drag still marks the terminal as focused and claims its size as before. Only the input focus waits for a tap. - Move the test tap into a helper. - Leave the native fullscreen scrolling change, its tests, the inertial gesture check, and the QA video out of this branch. They belong to #7762. Refs #9481 Co-authored-by: Tony Co-Authored-By: Claude Opus 5.5 * fix(app): keep an open keyboard open when you swipe the browser terminal A touch drag blurred the terminal input to stop Android from reopening a keyboard that Back had hidden. It also closed a keyboard that was open, so scrolling while typing needed a new tap. Blur only when the visual viewport shows no software keyboard. Co-Authored-By: Claude Opus 5.5 * Preserve the Android terminal keyboard state on swipe --------- Co-authored-by: Tony Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../app/e2e/browser/terminal-find.spec.ts | 62 +++++++++++++++++++ .../app/src/components/terminal-emulator.tsx | 54 ++++++++++++++-- .../runtime/terminal-emulator-runtime.ts | 7 +++ 3 files changed, 119 insertions(+), 4 deletions(-) diff --git a/packages/app/e2e/browser/terminal-find.spec.ts b/packages/app/e2e/browser/terminal-find.spec.ts index 26a5b5206..a362de780 100644 --- a/packages/app/e2e/browser/terminal-find.spec.ts +++ b/packages/app/e2e/browser/terminal-find.spec.ts @@ -503,6 +503,34 @@ test.describe("terminal history with a finger", () => { await expectMouseWheelScrollsHistory(page); }); + test("finger scrolling leaves terminal input unfocused until a tap", async ({ page }) => { + await openPhoneTerminalHistory(page); + await blurTerminalInput(page); + + await expectSingleFingerScroll(page, 24); + await expect(input(page)).not.toBeFocused(); + await expectSingleFingerScroll(page, 1); + await expect(input(page)).not.toBeFocused(); + + await tapTerminalScreen(page); + await expect(input(page)).toBeFocused(); + }); + + test("finger scrolling keeps a floating keyboard's input focused", async ({ page }) => { + await openPhoneTerminalHistory(page); + await tapTerminalScreen(page); + await expect(input(page)).toBeFocused(); + + // A floating keyboard leaves the visual viewport unchanged. + await expectSingleFingerScroll(page, 24); + await expect(input(page)).toBeFocused(); + await expect(input(page)).toHaveAttribute("virtualkeyboardpolicy", "manual"); + + // Android Back also leaves the input focused. A tap restores automatic keyboard opening. + await tapTerminalScreen(page); + await expect(input(page)).not.toHaveAttribute("virtualkeyboardpolicy"); + }); + for (const mode of ["alternate", "mouse"] as const) { test(`preserves finger navigation in ${mode} input mode`, async ({ page }) => { await openPhoneInputCapture(page, mode); @@ -531,6 +559,26 @@ async function openPhoneTerminalHistory(page: Page) { }); await openPhoneTerminal(page); await expect.poll(() => getTerminalBufferText(page)).toContain("HISTORY_150"); + await expect + .poll(() => page.evaluate(() => window.__paseoTerminal!.buffer.active.baseY)) + .toBeGreaterThan(0); + await page.evaluate(() => window.__paseoTerminal!.scrollToBottom()); + await expect.poll(() => viewport(page)).toBeGreaterThan(0); +} + +function terminalScreen(page: Page) { + return page.getByTestId("terminal-surface").filter({ visible: true }).locator(".xterm-screen"); +} + +async function tapTerminalScreen(page: Page) { + const box = await terminalScreen(page).boundingBox(); + expect(box).not.toBeNull(); + await page.touchscreen.tap(box!.x + box!.width / 2, box!.y + box!.height / 3); +} + +async function blurTerminalInput(page: Page) { + await input(page).evaluate((element) => element.blur()); + await expect(input(page)).not.toBeFocused(); } async function openPhoneInputCapture(page: Page, mode: "alternate" | "mouse") { @@ -570,6 +618,20 @@ async function openPhoneTerminal(page: Page) { await page.getByTestId(`sidebar-workspace-row-${getServerId()}:${harness.workspaceId}`).click(); await expect(page.getByRole("textbox", { name: "Terminal input" })).toBeVisible(); await expect(page.getByTestId("terminal-surface").filter({ visible: true })).toBeVisible(); + // The terminal stays mounted while the sidebar's closing backdrop still intercepts input. + await expect + .poll(() => + page + .getByTestId("terminal-surface") + .filter({ visible: true }) + .evaluate((root) => { + const box = root.querySelector(".xterm-screen")!.getBoundingClientRect(); + return root.contains( + document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 3), + ); + }), + ) + .toBe(true); } async function expectMouseWheelScrollsHistory(page: Page) { diff --git a/packages/app/src/components/terminal-emulator.tsx b/packages/app/src/components/terminal-emulator.tsx index 7504843c5..61b24ea92 100644 --- a/packages/app/src/components/terminal-emulator.tsx +++ b/packages/app/src/components/terminal-emulator.tsx @@ -13,6 +13,7 @@ import { useRef, type CSSProperties, type MouseEvent as ReactMouseEvent, + type PointerEvent as ReactPointerEvent, type Ref, } from "react"; import type { DOMProps } from "expo/dom"; @@ -63,6 +64,12 @@ const HOST_DIV_STYLE: CSSProperties = { paddingRight: 0, }; +interface TerminalTouchFocus { + pointerId: number; + x: number; + y: number; +} + function buildXtermThemeKey(theme: ITheme): string { const values: Array = [ theme.background, @@ -553,10 +560,46 @@ export default function TerminalEmulator({ }); }, []); - const handleRootPointerDown = useCallback(() => { - onFocus?.(); - runtimeRef.current?.focus(); - }, [onFocus]); + const touchFocusRef = useRef(null); + + const handleRootPointerDown = useCallback( + (event: ReactPointerEvent) => { + onFocus?.(); + touchFocusRef.current = null; + if (event.pointerType !== "touch") { + runtimeRef.current?.focus(); + return; + } + // Focusing before a touch becomes a tap opens the keyboard during a scroll. + if (event.isPrimary) { + touchFocusRef.current = { + pointerId: event.pointerId, + x: event.clientX, + y: event.clientY, + }; + } + }, + [onFocus], + ); + + const handleRootPointerMove = useCallback((event: ReactPointerEvent) => { + const touch = touchFocusRef.current; + if (touch?.pointerId !== event.pointerId) return; + if (Math.hypot(event.clientX - touch.x, event.clientY - touch.y) > 8) { + touchFocusRef.current = null; + runtimeRef.current?.suppressAutomaticKeyboard(); + } + }, []); + + const handleRootPointerUp = useCallback((event: ReactPointerEvent) => { + const touch = touchFocusRef.current; + touchFocusRef.current = null; + if (touch?.pointerId === event.pointerId) runtimeRef.current?.focus(); + }, []); + + const handleRootPointerCancel = useCallback(() => { + touchFocusRef.current = null; + }, []); const handleRootContextMenu = useCallback( (event: ReactMouseEvent) => { @@ -588,6 +631,9 @@ export default function TerminalEmulator({ data-terminal-scrollbar-root="true" style={rootDivStyle} onPointerDown={handleRootPointerDown} + onPointerMove={handleRootPointerMove} + onPointerUp={handleRootPointerUp} + onPointerCancel={handleRootPointerCancel} onContextMenu={handleRootContextMenu} >
diff --git a/packages/app/src/terminal/runtime/terminal-emulator-runtime.ts b/packages/app/src/terminal/runtime/terminal-emulator-runtime.ts index 3aaf1e139..f538c39bc 100644 --- a/packages/app/src/terminal/runtime/terminal-emulator-runtime.ts +++ b/packages/app/src/terminal/runtime/terminal-emulator-runtime.ts @@ -1053,12 +1053,19 @@ export class TerminalEmulatorRuntime { if (!terminal) { return; } + terminal.textarea?.removeAttribute("virtualkeyboardpolicy"); if (input?.forceRefocus) { terminal.blur(); } terminal.focus(); } + suppressAutomaticKeyboard(): void { + // Android Chrome can reopen the keyboard during a drag after Back leaves the input + // focused. Manual policy prevents that without closing an already open keyboard. + this.terminal?.textarea?.setAttribute("virtualkeyboardpolicy", "manual"); + } + blur(): void { this.terminal?.blur(); }