Compare commits

...
Author SHA1 Message Date
paseo-bot[bot]andClaude Opus 5.5 550f85e1ae 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 <noreply@anthropic.com>
2026-11-19 13:18:32 +00:00
c016c161cc 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 <liutuo@outlook.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 12:30:33 +00:00
Tony 83e1f0b041 fix(terminal): restore mobile scrolling and touch keyboard focus 2026-11-19 12:28:42 +00:00
2 changed files with 131 additions and 4 deletions
@@ -503,6 +503,35 @@ test.describe("terminal history with a finger", () => {
await expectMouseWheelScrollsHistory(page);
});
test("finger scrolling leaves the keyboard closed and a tap focuses input", async ({ page }) => {
await openPhoneTerminalHistory(page);
await input(page).evaluate((element) => element.blur());
await expect(input(page)).not.toBeFocused();
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();
// Android's Back button hides the IME without blurring this input.
await expectSingleFingerScroll(page, 24);
await expect(input(page)).not.toBeFocused();
await terminalScreen(page).click();
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);
@@ -531,6 +560,32 @@ 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);
}
// 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") {
@@ -570,6 +625,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) {
@@ -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,22 @@ const HOST_DIV_STYLE: CSSProperties = {
paddingRight: 0,
};
interface TerminalTouchFocus {
pointerId: number;
x: number;
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<string> = [
theme.background,
@@ -553,10 +570,48 @@ export default function TerminalEmulator({
});
}, []);
const handleRootPointerDown = useCallback(() => {
onFocus?.();
runtimeRef.current?.focus();
}, [onFocus]);
const touchFocusRef = useRef<TerminalTouchFocus | null>(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;
// 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();
}
}, []);
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 +643,9 @@ export default function TerminalEmulator({
data-terminal-scrollbar-root="true"
style={rootDivStyle}
onPointerDown={handleRootPointerDown}
onPointerMove={handleRootPointerMove}
onPointerUp={handleRootPointerUp}
onPointerCancel={handleRootPointerCancel}
onContextMenu={handleRootContextMenu}
>
<div ref={hostRef} style={HOST_DIV_STYLE} />