Skip to content

fix(terminal): make scroll wheel work again in alternate screen#42

Merged
amirlehmam merged 1 commit into
amirlehmam:masterfrom
egertaia:fix/scroll-in-terminal
Jun 20, 2026
Merged

fix(terminal): make scroll wheel work again in alternate screen#42
amirlehmam merged 1 commit into
amirlehmam:masterfrom
egertaia:fix/scroll-in-terminal

Conversation

@egertaia

@egertaia egertaia commented Jun 18, 2026

Copy link
Copy Markdown

Fixes #41

Summary

  • Fixes scroll wheel regression in alternate-screen apps (Claude Code, vim, less, htop) introduced in v0.8.4+
  • When on the alternate buffer, takes ownership of wheel events and forwards them to the PTY directly instead of relying on xterm's _handleWheel / _handlePassiveWheel which are unreliable after the WebGL context swap
  • Sends SGR mouse-wheel sequences (\x1b[<64;col;rowM / \x1b[<65;col;rowM) when the app has enabled mouse tracking, falls back to arrow keys otherwise

Root cause

xterm's built-in wheel forwarding fails in two cases:

  1. The wheel listener is only registered when the app has explicitly requested wheel mouse events via DECSET
  2. _consumeWheelEvent returns 0 when render-service cell dimensions are temporarily unavailable (can happen after the WebGL renderer swap in v0.8.4+), causing the event to be silently dropped

Test plan

  • Scroll in a normal terminal — scrollback works as before
  • Scroll inside Claude Code / vim / less — content scrolls correctly
  • Scroll in a TUI without mouse tracking enabled — arrow keys sent, content moves

🤖 Generated with Claude Code

@amirlehmam amirlehmam merged commit 644470b into amirlehmam:master Jun 20, 2026
amirlehmam added a commit that referenced this pull request Jun 20, 2026
…close (fixes #47)

Resolved overlap with PR #42 in useTerminal.ts: unified the wheel handler so it
always takes ownership on the capture phase (alt-buffer ownership + arrow-key
fallback from #42, reliable surfaceMouseEnabled signal + pre-attach resize
handling from #48). Extracted the wheel handler and initial/deferred resize into
module-level helpers to keep the mount effect within complexity limits.
@amirlehmam

Copy link
Copy Markdown
Owner

Merged and shipped in v0.8.8 🚀 Thanks @kevmtt! Your alt-buffer ownership fix (#41) is the foundation of the unified wheel handler — I merged it together with #48 (the webview/tmux case). Since the handler now always takes ownership on the capture phase, the SGR-vs-arrow-keys decision uses #48's remount-safe surfaceMouseEnabled signal while keeping your arrow-key fallback for non-mouse pagers. See the note on #48 for the full resolution.

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.

Mouse wheel scroll broken inside Claude Code (alternate screen buffer) — v0.8.7

2 participants