Skip to content

fix(terminal): enable touch-scroll in alternate buffer with mouse tracking#383

Merged
danshapiro merged 1 commit into
mainfrom
fix/mobile-opencode-touch-scroll
Jun 2, 2026
Merged

fix(terminal): enable touch-scroll in alternate buffer with mouse tracking#383
danshapiro merged 1 commit into
mainfrom
fix/mobile-opencode-touch-scroll

Conversation

@danshapiro
Copy link
Copy Markdown
Owner

For providers with the native scrollInputPolicy (the default), touch swipes in alternate buffer + mouse-tracking mode formerly fell through to scrollLines, which is a no-op in xterm.js alternate buffers because they have no scrollback.

Changes

Implementation

  • Dispatches synthetic WheelEvents directly to term.element when native policy is active and terminal is in alternate buffer with mouse tracking
  • xterm.js translates these into mouse-wheel CSI sequences sent to the PTY, matching desktop wheel behavior
  • Includes position data (clientX/clientY) on synthetic events for accurate mouse tracking
  • Falls back to term.scrollLines() for normal buffer or non-native policy

Fixes

  • Removes dead shouldSuppressNativeTouchScroll helper (always returned false)
  • Fixes variable shadowing (renames inner deltaY to scrollDirection)

Tests

  • Native policy wheel dispatch (direction, multi-line swipes, deltaMode)
  • term.element == null fallback
  • Cursor-key fallback policy
  • Normal buffer scrollLines behavior

Fresheyes

Passed 4th review (3rd after fixes).

…cking

For providers with the native scrollInputPolicy (the default), touch
swipes in alternate buffer + mouse-tracking mode formerly fell through to
scrollLines, which is a no-op in xterm.js alternate buffers because they
have no scrollback.

Fix: when native policy is active and the terminal is in alternate buffer
with mouse tracking on, dispatch synthetic WheelEvents directly to
term.element. xterm.js translates these into mouse-wheel CSI sequences
sent to the PTY, matching desktop wheel behavior.

Includes position data (clientX/clientY) on synthetic events for accurate
mouse tracking in TUIs with multiple scrollable regions.

Tests cover:
- Native policy wheel dispatch (upward and downward direction, multi-line
  swipes producing repeated events, correct deltaMode).
- term.element == null fallback to scrollLines.
- Fallback-to-cursor-keys policy sends cursor key sequences.
- Normal buffer continues to call scrollLines as before.
@danshapiro danshapiro merged commit 2c8978e into main Jun 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants