fix(scroll): keep mouse wheel / trackball scrollable past a stale-small clamp#71
Merged
Merged
Conversation
…ll clamp clampToInsets() clamps against scrollableContentHeight, derived from a cached TextKit-2 measurement that can under-measure. A continuous trackpad refreshes that cache mid-gesture, but a discrete device (classic mouse wheel, Ploopy trackball) sends one event with no relayout, so a stale-small height clamps every tick straight back = "scroll doesn't work". When a clamp-back is imminent, force one fresh full-layout re-measure and clamp against the corrected height. Self-limiting (only fires at the bottom) and still clamps to the real content height, so short docs can't scroll into the click-below inflation area. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
luca-chen198
added a commit
that referenced
this pull request
Jun 20, 2026
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.
Problem
Discrete-delta input devices (classic mouse wheel, Ploopy trackball) intermittently can't scroll the editor; a brief trackpad scroll "revives" it.
Root cause
ClampedScrollView.scrollWheelrunsclampToInsets()after every event, clamping the max scroll againstscrollableContentHeight, which derives from a cached TextKit-2 measurement (baseContentHeight) that can under-measure / settle on a too-small value. A continuous trackpad gesture keeps firing relayout/recalcOverscrollmid-gesture and refreshes that cache, so it escapes the clamp. A discrete device delivers a single event with no relayout in between, so a stale-small height clamps each tick straight back to the same spot → "scroll doesn't work".Fix
In
clampToInsets(), when a clamp-back is imminent (b.origin.y > realHeight - b.height), force one fresh full-layout re-measure and clamp against the corrected height — i.e. make the trackpad's free re-measure deterministic for discrete devices.Invariants preserved
No scroll-into-empty for short docs, bottom overscroll + scroll-away header, reading-column centering, file-switch no-drift, live-resize save/restore — all unchanged (the fix only changes when the height is re-validated).
Tests
swift buildclean;swift test90/90 green.🤖 Generated with Claude Code