From 550f85e1ae1cdca0788712ddda0a2f4dd54bfea6 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:18:32 +0000 Subject: [PATCH] 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 --- .../app/e2e/browser/terminal-find.spec.ts | 21 +++++++++++++++++++ .../app/src/components/terminal-emulator.tsx | 15 +++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/app/e2e/browser/terminal-find.spec.ts b/packages/app/e2e/browser/terminal-find.spec.ts index 4be98c3e69..0ec6ece29a 100644 --- a/packages/app/e2e/browser/terminal-find.spec.ts +++ b/packages/app/e2e/browser/terminal-find.spec.ts @@ -522,6 +522,16 @@ test.describe("terminal history with a finger", () => { await expect(input(page)).toBeFocused(); }); + test("finger scrolling keeps an open keyboard open", async ({ page }) => { + await openPhoneTerminalHistory(page); + await tapTerminalScreen(page); + await expect(input(page)).toBeFocused(); + + await showSoftwareKeyboard(page); + await expectSingleFingerScroll(page, 24); + await expect(input(page)).toBeFocused(); + }); + for (const mode of ["alternate", "mouse"] as const) { test(`preserves finger navigation in ${mode} input mode`, async ({ page }) => { await openPhoneInputCapture(page, mode); @@ -567,6 +577,17 @@ async function tapTerminalScreen(page: Page) { await page.touchscreen.tap(box!.x + box!.width / 2, box!.y + box!.height / 3); } +// Playwright cannot show a software keyboard. A phone browser keeps the layout +// viewport and shortens the visual viewport by the keyboard height. +async function showSoftwareKeyboard(page: Page) { + await page.evaluate(() => { + Object.defineProperty(window.visualViewport!, "height", { + configurable: true, + get: () => window.innerHeight - 300, + }); + }); +} + async function openPhoneInputCapture(page: Page, mode: "alternate" | "mouse") { const escapes = mode === "alternate" ? "\x1b[?1049h\x1b[?1h" : "\x1b[?1000h\x1b[?1006h"; await harness.createTerminal({ diff --git a/packages/app/src/components/terminal-emulator.tsx b/packages/app/src/components/terminal-emulator.tsx index 33c4b910bb..f543a2470f 100644 --- a/packages/app/src/components/terminal-emulator.tsx +++ b/packages/app/src/components/terminal-emulator.tsx @@ -70,6 +70,16 @@ interface TerminalTouchFocus { y: number; } +// A phone browser shortens the visual viewport, not the layout viewport, for its keyboard. +const SOFTWARE_KEYBOARD_MIN_HEIGHT_PX = 100; + +function isSoftwareKeyboardShown(): boolean { + const viewport = window.visualViewport; + if (!viewport) return false; + const visibleHeight = viewport.height * viewport.scale; + return window.innerHeight - visibleHeight > SOFTWARE_KEYBOARD_MIN_HEIGHT_PX; +} + function buildXtermThemeKey(theme: ITheme): string { const values: Array = [ theme.background, @@ -587,8 +597,9 @@ export default function TerminalEmulator({ if (touch?.pointerId !== event.pointerId) return; if (Math.hypot(event.clientX - touch.x, event.clientY - touch.y) > 8) { touchFocusRef.current = null; - // Android can reopen a dismissed keyboard after a drag while input still has focus. - runtimeRef.current?.blur(); + // Android Back hides the keyboard but leaves the input focused, and a drag + // on a focused input reopens it. An open keyboard stays open while scrolling. + if (!isSoftwareKeyboardShown()) runtimeRef.current?.blur(); } }, []);