diff --git a/docs/qa-evidence/android-terminal-touch.webm b/docs/qa-evidence/android-terminal-touch.webm deleted file mode 100644 index 8f629d5d54..0000000000 Binary files a/docs/qa-evidence/android-terminal-touch.webm and /dev/null differ diff --git a/packages/app/e2e/browser/terminal-find.spec.ts b/packages/app/e2e/browser/terminal-find.spec.ts index fe545971d7..4be98c3e69 100644 --- a/packages/app/e2e/browser/terminal-find.spec.ts +++ b/packages/app/e2e/browser/terminal-find.spec.ts @@ -513,18 +513,12 @@ test.describe("terminal history with a finger", () => { await expectSingleFingerScroll(page, 1); await expect(input(page)).not.toBeFocused(); - const screen = page - .getByTestId("terminal-surface") - .filter({ visible: true }) - .locator(".xterm-screen"); - const box = await screen.boundingBox(); - if (!box) throw new Error("Terminal screen is not visible"); - await page.touchscreen.tap(box.x + box.width / 2, box.y + box.height / 3); + 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 screen.click(); + await terminalScreen(page).click(); await expect(input(page)).toBeFocused(); }); @@ -532,19 +526,6 @@ test.describe("terminal history with a finger", () => { test(`preserves finger navigation in ${mode} input mode`, async ({ page }) => { await openPhoneInputCapture(page, mode); await expectFingerNavigationInput(page, mode); - // xterm's inertial gesture has translation but no new pointer coordinates. - await page - .locator(".xterm-screen") - .filter({ visible: true }) - .evaluate((screen) => { - const event = new CustomEvent("-xterm-gesturechange", { cancelable: true }); - Object.assign(event, { translationX: 0, translationY: 120 }); - screen.dispatchEvent(event); - }); - // A following byte is a PTY round-trip barrier for the gesture's reports. - await input(page).press("z"); - await expect.poll(() => getTerminalBufferText(page)).toContain("TOUCH_BYTES:7a:END"); - expect(await getTerminalBufferText(page)).not.toContain("INVALID_TOUCH_INPUT"); }); } }); @@ -576,6 +557,16 @@ async function openPhoneTerminalHistory(page: Page) { 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 openPhoneInputCapture(page: Page, mode: "alternate" | "mouse") { const escapes = mode === "alternate" ? "\x1b[?1049h\x1b[?1h" : "\x1b[?1000h\x1b[?1006h"; await harness.createTerminal({ @@ -587,9 +578,6 @@ async function openPhoneInputCapture(page: Page, mode: "alternate" | "mouse") { process.stdin.setRawMode(true); process.stdin.once("data", () => { process.stdin.on("data", chunk => { - if (chunk.includes(Buffer.from("NaN"))) { - process.stdout.write("\\r\\nINVALID_TOUCH_INPUT\\r\\n"); - } process.stdout.write("\\r\\nTOUCH_BYTES:" + chunk.toString("hex") + ":END\\r\\n"); }); process.stdout.write(${JSON.stringify(escapes)} + "TOUCH_INPUT_READY\\r\\n"); diff --git a/packages/app/src/components/terminal-emulator-native-grid.native.tsx b/packages/app/src/components/terminal-emulator-native-grid.native.tsx index 41a9dc3d05..e76905b327 100644 --- a/packages/app/src/components/terminal-emulator-native-grid.native.tsx +++ b/packages/app/src/components/terminal-emulator-native-grid.native.tsx @@ -557,25 +557,6 @@ function NativeTerminalEmulator({ if (!terminal || !model || rows <= 0) { return; } - const metrics = metricsRef.current; - if (!selectionRangeRef.current && metrics) { - const point = gestureStartRef.current; - const applicationInput = terminal.getScrollInput({ - direction, - rows, - column: Math.floor(point.x / metrics.cellWidth) + 1, - row: Math.floor(point.y / metrics.cellHeight) + 1, - x: Math.floor(point.x) + 1, - y: Math.floor(point.y) + 1, - }); - if (applicationInput !== null) { - if (applicationInput.length > 0) { - claimActiveTerminalSize(); - callbacksRef.current.onInput?.(applicationInput); - } - return; - } - } const visibleRows = resolveVisibleRows(terminal); const screen = direction === "up" @@ -583,7 +564,7 @@ function NativeTerminalEmulator({ : model.scrollDown({ rows, visibleRows }); commitTerminalScreen(screen); }, - [claimActiveTerminalSize, commitTerminalScreen, resolveVisibleRows], + [commitTerminalScreen, resolveVisibleRows], ); const returnToBottom = useCallback(() => { diff --git a/packages/app/src/components/terminal-emulator.tsx b/packages/app/src/components/terminal-emulator.tsx index c27c4965a0..33c4b910bb 100644 --- a/packages/app/src/components/terminal-emulator.tsx +++ b/packages/app/src/components/terminal-emulator.tsx @@ -561,28 +561,25 @@ export default function TerminalEmulator({ }, []); const touchFocusRef = useRef(null); - const focusTerminalFromPointer = useCallback(() => { - onFocus?.(); - runtimeRef.current?.focus(); - }, [onFocus]); const handleRootPointerDown = useCallback( (event: ReactPointerEvent) => { + onFocus?.(); touchFocusRef.current = null; - if (event.pointerType === "touch") { - // 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, - }; - } + if (event.pointerType !== "touch") { + runtimeRef.current?.focus(); return; } - focusTerminalFromPointer(); + // 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, + }; + } }, - [focusTerminalFromPointer], + [onFocus], ); const handleRootPointerMove = useCallback((event: ReactPointerEvent) => { @@ -595,14 +592,11 @@ export default function TerminalEmulator({ } }, []); - const handleRootPointerUp = useCallback( - (event: ReactPointerEvent) => { - const touch = touchFocusRef.current; - touchFocusRef.current = null; - if (touch?.pointerId === event.pointerId) focusTerminalFromPointer(); - }, - [focusTerminalFromPointer], - ); + 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; diff --git a/packages/app/src/terminal/native-renderer/headless-terminal-state.test.ts b/packages/app/src/terminal/native-renderer/headless-terminal-state.test.ts index 877090c08f..546982906f 100644 --- a/packages/app/src/terminal/native-renderer/headless-terminal-state.test.ts +++ b/packages/app/src/terminal/native-renderer/headless-terminal-state.test.ts @@ -19,53 +19,6 @@ function expectedBenchmarkLine(index: number): string { } describe("native headless terminal state", () => { - test("routes alternate-screen finger scrolling to the application's cursor keys", async () => { - const terminal = createNativeHeadlessTerminal({ rows: 5, cols: COLS }); - const scroll = { direction: "up" as const, rows: 2, column: 4, row: 3, x: 24, y: 40 }; - expect(terminal.getScrollInput(scroll)).toBeNull(); - - await terminal.write("\x1b[?1049h\x1b[?1h"); - const bounds = terminal.getBufferBounds(); - expect(bounds.oldestRow).toBe(bounds.bottomViewport.firstRow); - expect(terminal.getScrollInput(scroll)).toBe("\x1bOA\x1bOA"); - expect(terminal.getScrollInput({ ...scroll, direction: "down", rows: 1 })).toBe("\x1bOB"); - - await terminal.write("\x1b[?1l"); - expect(terminal.getScrollInput({ ...scroll, rows: 1 })).toBe("\x1b[A"); - await terminal.write("\x1b[?1049l"); - expect(terminal.getScrollInput(scroll)).toBeNull(); - terminal.dispose(); - }); - - test.each([1000, 1002, 1003])( - "routes finger scrolling through mouse tracking mode %i", - async (mode) => { - const terminal = createNativeHeadlessTerminal({ rows: 5, cols: COLS }); - const scroll = { direction: "up" as const, rows: 2, column: 4, row: 3, x: 24, y: 40 }; - await terminal.write(`\x1b[?1049h\x1b[?${mode}h\x1b[?1006h`); - expect(terminal.getScrollInput(scroll)).toBe("\x1b[<64;4;3M\x1b[<64;4;3M"); - expect(terminal.getScrollInput({ ...scroll, direction: "down", rows: 1 })).toBe( - "\x1b[<65;4;3M", - ); - - await terminal.write(`\x1b[?${mode}l`); - expect(terminal.getScrollInput({ ...scroll, rows: 1 })).toBe("\x1b[A"); - terminal.dispose(); - }, - ); - - test("keeps xterm's legacy and pixel mouse encodings for finger scroll input", async () => { - const terminal = createNativeHeadlessTerminal({ rows: 5, cols: COLS }); - const scroll = { direction: "up" as const, rows: 1, column: 4, row: 3, x: 24, y: 40 }; - await terminal.write("\x1b[?1000h"); - expect(terminal.getScrollInput(scroll)).toBe("\x1b[M`$#"); - await terminal.write("\x1b[?1006h\x1b[?1016h"); - expect(terminal.getScrollInput(scroll)).toBe("\x1b[<64;24;40M"); - terminal.reset(); - expect(terminal.getScrollInput(scroll)).toBeNull(); - terminal.dispose(); - }); - test("exposes application cursor key mode from headless xterm", async () => { const terminal = createNativeHeadlessTerminal({ rows: 5, cols: COLS }); diff --git a/packages/app/src/terminal/native-renderer/headless-terminal-state.ts b/packages/app/src/terminal/native-renderer/headless-terminal-state.ts index 638342a847..4347588861 100644 --- a/packages/app/src/terminal/native-renderer/headless-terminal-state.ts +++ b/packages/app/src/terminal/native-renderer/headless-terminal-state.ts @@ -27,7 +27,6 @@ export interface NativeHeadlessTerminal { write(data: NativeTerminalWriteData): Promise; getViewportState(input?: TerminalViewportStateInput): TerminalViewportState; getInputModeState(): NativeHeadlessTerminalInputModeState; - getScrollInput(input: NativeTerminalScrollInput): string | null; getBufferBounds(): TerminalBufferBounds; getBufferWindow(input: TerminalBufferWindowInput): TerminalBufferWindow; resize(input: { rows: number; cols: number }): void; @@ -35,15 +34,6 @@ export interface NativeHeadlessTerminal { dispose(): void; } -export interface NativeTerminalScrollInput { - direction: "up" | "down"; - rows: number; - column: number; - row: number; - x: number; - y: number; -} - export interface NativeHeadlessTerminalInputModeState { applicationCursorKeys: boolean; bracketedPaste: boolean; @@ -105,9 +95,6 @@ interface XtermCoreService { interface HeadlessTerminalWithCore { _core?: { coreService?: XtermCoreService; - mouseStateService?: { - encodeMouseEvent(event: XtermMouseWheelEvent): string; - }; _bufferService?: { buffer?: { lines?: { @@ -118,18 +105,6 @@ interface HeadlessTerminalWithCore { }; } -interface XtermMouseWheelEvent { - col: number; - row: number; - x: number; - y: number; - button: 4; - action: 0 | 1; - ctrl: boolean; - alt: boolean; - shift: boolean; -} - interface TerminalCoordinateStorage { oldestRow: number; trimSubscription: { dispose(): void } | null; @@ -383,34 +358,6 @@ export function createNativeHeadlessTerminal( getInputModeState(): NativeHeadlessTerminalInputModeState { return extractInputModeState(terminal); }, - getScrollInput(input: NativeTerminalScrollInput): string | null { - const mouseMode = terminal.modes.mouseTrackingMode; - const reportsWheel = mouseMode !== "none" && mouseMode !== "x10"; - if (reportsWheel) { - // Use the pinned xterm encoder so SGR, legacy and pixel reports follow the same modes - // as the web terminal. The native view supplies one-based cell and pixel coordinates. - const mouse = (terminal as unknown as HeadlessTerminalWithCore)._core?.mouseStateService; - if (!mouse) throw new Error("Native terminal mouse encoder is unavailable"); - const report = mouse.encodeMouseEvent({ - col: Math.max(1, Math.min(terminal.cols, input.column)), - row: Math.max(1, Math.min(terminal.rows, input.row)), - x: input.x, - y: input.y, - button: 4, - action: input.direction === "up" ? 0 : 1, - ctrl: false, - alt: false, - shift: false, - }); - return report.repeat(input.rows); - } - if (terminal.buffer.active.type === "alternate") { - const prefix = terminal.modes.applicationCursorKeysMode ? "\x1bO" : "\x1b["; - const key = input.direction === "up" ? "A" : "B"; - return `${prefix}${key}`.repeat(input.rows); - } - return null; - }, getBufferBounds(): TerminalBufferBounds { return extractBufferBounds(terminal, coordinateEpoch, getActiveCoordinateStorage().oldestRow); },