mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-19 23:05:21 +00:00
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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c016c161cc
commit
550f85e1ae
@@ -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({
|
||||
|
||||
@@ -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<string> = [
|
||||
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();
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user