Fix NaN coordinates in mouse wheel reports from touch fling inertia - #6059
Open
tajo wants to merge 1 commit into
Open
Fix NaN coordinates in mouse wheel reports from touch fling inertia#6059tajo wants to merge 1 commit into
tajo wants to merge 1 commit into
Conversation
Inertia (fling momentum) CHANGE events carried only translationX/Y, while real touchmove CHANGE events also carry page/client coordinates. The mouse-report wheel path (_handleTouchScrollAsWheel) reads event.clientX/clientY to compute the reported cell position, which produced NaN coordinates that passed through getMouseReportCoords' clamping untouched and were serialized into wheel reports (e.g. `CSI < 64 ; NaN ; NaN M`) — applications with mouse tracking enabled (vim with mouse=a, tmux, agent TUIs) received them as garbage input on every fling release. Fix at the source by stamping the position the inertia animation already tracks onto the events (page coordinates; client derived via the window's scroll offsets), and defensively skip wheel reports for coordinate-less gesture events so malformed sequences can't reach the PTY from this path again. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
tajo
marked this pull request as ready for review
July 22, 2026 03:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found this problem when using 6.1.0-beta.291 on iPhone running
claude codeinside. Scrolling (touch fling) was causing garbage chars likeNaN;NaNMbeing inputed into the prompt. This fixes it.The rest is generated by Claude Fable.
Problem
Inertia (fling momentum) CHANGE events dispatched by
Gesture._inertia(src/browser/scrollable/touch.ts) carried onlytranslationX/Y, while real touchmove CHANGE events also carry page/client coordinates. The mouse-report wheel path (MouseService._handleTouchScrollAsWheel) readsevent.clientX/clientYto compute the reported cell position, which produced NaN coordinates that passed throughgetMouseReportCoords' clamping untouched and were serialized into wheel reports (e.g.CSI < 64 ; NaN ; NaN M) — applications with mouse tracking enabled (vim withmouse=a, tmux, agent TUIs) received them as garbage input on every fling release.Fix
Two additive changes (+18 lines):
src/browser/scrollable/touch.ts— fix at the source by stamping the position the inertia animation already tracks onto the momentum events (page coordinates; client derived via the window's scroll offsets), matching what_handleTouchMovestamps on real frames.src/browser/services/MouseService.ts— defensively skip wheel reports for coordinate-less gesture events (!isFinite(e.clientX) || !isFinite(e.clientY)) so malformed sequences can't reach the PTY from this path again.To reproduce
On a touch device (or DevTools touch emulation), run any app that enables mouse tracking (e.g. vim with
set mouse=a) in the demo, flick-scroll and lift — the app receivesESC[<64;NaN;NaNMper momentum tick, visible as literalNaN;NaNMinput. Discovered embedding xterm.js in a web dashboard terminal running an agent TUI with mouse reporting.Validation
npm run build(tsgo) cleannpm run esbuildcleannpm run test-unit— 2403 passing, 0 failingNo new test added — the touch handlers are private/DOM-wired and the unit harness has no gesture mocks; happy to add coverage wherever you'd prefer it.
🤖 Generated with Claude Code