Scroll terminal panes with a swipe on touch devices #131

Closed
alecraso wants to merge 1 commit from fix/touch-scroll into main
Collaborator

On a phone, swiping a terminal pane doesn't scroll it, with one finger or two.

Cause: xterm.js 6 replaced its natively scrollable viewport with VS Code's ScrollableElement, which only handles wheel. xterm ships a touch Gesture helper but never registers a target, and TerminalView added no touch handling, so swipes were dropped.

Fix (web/src/terminal-view.ts): turn vertical swipes into scrolling.

  • Normal buffer, no mouse tracking: scrollLines, following the finger row by row, with a decaying fling on release.
  • Mouse tracking: a synthetic line-mode wheel on .xterm-screen, so the program gets wheel reports at the touch position.
  • Alt screen without mouse: the same wheel event, which xterm turns into arrow keys.
  • Taps are untouched (8px slop), so tapping still focuses the terminal and brings up the keyboard.

Tested with Playwright Chromium emulating a Pixel 7, driving real CDP touch events:

before after
swipe in scrollback no movement scrolls, fling continues
mouse tracking (SGR) nothing sent ESC[<64;…M wheel reports
alt screen, no mouse nothing sent ESC[A arrows
tap focuses textarea unchanged

tsc --noEmit passes. Not yet tried on a physical device; iOS Safari is untested.

🤖 Generated with Claude Code

On a phone, swiping a terminal pane doesn't scroll it, with one finger or two. **Cause:** xterm.js 6 replaced its natively scrollable viewport with VS Code's `ScrollableElement`, which only handles `wheel`. xterm ships a touch `Gesture` helper but never registers a target, and `TerminalView` added no touch handling, so swipes were dropped. **Fix** (`web/src/terminal-view.ts`): turn vertical swipes into scrolling. - Normal buffer, no mouse tracking: `scrollLines`, following the finger row by row, with a decaying fling on release. - Mouse tracking: a synthetic line-mode `wheel` on `.xterm-screen`, so the program gets wheel reports at the touch position. - Alt screen without mouse: the same wheel event, which xterm turns into arrow keys. - Taps are untouched (8px slop), so tapping still focuses the terminal and brings up the keyboard. **Tested** with Playwright Chromium emulating a Pixel 7, driving real CDP touch events: | | before | after | |---|---|---| | swipe in scrollback | no movement | scrolls, fling continues | | mouse tracking (SGR) | nothing sent | `ESC[<64;…M` wheel reports | | alt screen, no mouse | nothing sent | `ESC[A` arrows | | tap | focuses textarea | unchanged | `tsc --noEmit` passes. Not yet tried on a physical device; iOS Safari is untested. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Scroll terminal panes with a swipe on touch devices
All checks were successful
check / macos (push) Successful in 4m48s
check / linux (push) Successful in 6m27s
b5982c09ba
xterm.js 6's viewport is VS Code's scrollable element, which scrolls on
the wheel only; its touch Gesture helper has no targets, so swipes did
nothing. Turn vertical swipes into scrolling: the scrollback directly
(with a fling), or synthetic wheel events when a program wants them
(mouse reports, alt-screen arrows). Taps still focus the terminal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Collaborator

illogical has moved to GitHub, so this continues there: https://github.com/arugula-salad/illogical/pull/93 (same commit). Closing this one.

illogical has moved to GitHub, so this continues there: https://github.com/arugula-salad/illogical/pull/93 (same commit). Closing this one.
alecraso closed this pull request 2026-10-04 04:01:34 +00:00
Commenting is not possible because the repository is archived.
No description provided.