Fix Ghostty viewport sync scroll jitter
LA
8mo ago+682+682+012345678901234567890123456789-35-35-01234567890123456789
Summary
Restart from current main and rebuild the Ghostty viewport sync fix with a fresh red/green pair.
- add a pure viewport sync helper plus regression coverage for anchor preservation, explicit scroll consumption, stale passive updates, and AppKit row mapping
- keep Ghostty top-visible-row state separate from AppKit bottom-origin scroll distance
- use accepted scrollbar state and stored top-row anchors in
GhosttyTerminalViewso plain scrolling and passive updates stop fighting each other
Verification
./tests/test_ghostty_viewport_sync_logic.shxcodebuild -project GhosttyTabs.xcodeproj -scheme cmux-unit -destination "platform=macOS" -derivedDataPath /tmp/cmux-task-scroll-jank-reset-green4 -only-testing:cmuxTests/GhosttyScrollbarSyncPlanTests test./scripts/reload.sh --tag task-scroll-jank-reset
Summary by cubic
Fixes scroll jitter in Ghostty by separating explicit user scrolls from passive output updates and anchoring the top visible row. Adds a stateless viewport sync planner to stabilize scrollbar-to-viewport mapping and prevent rubber-banding.
-
Bug Fixes
- Marks explicit viewport changes on wheel and user-initiated binding actions, and treats output updates as passive to avoid conflicts.
- Stores the top-visible-row anchor and reconciles passive scrollbar snapshots to that anchor; uses AppKit’s row-from-bottom mapping for accurate targets.
- Ignores regressive/stale passive snapshots while reviewing scrollback to prevent anchor loss and jitter.
-
Refactors
- Extracted sync logic into
GhosttyViewportSync.swiftwith small, pure helpers used byGhosttySurfaceScrollView/GhosttyTerminalView. - Added
GhosttyScrollbarSyncPlanTests.swiftand a lightweight CLI test (tests/test_ghostty_viewport_sync_logic.*); wired tests into the Xcode project.
- Extracted sync logic into
Summary by CodeRabbit
-
New Features
- Enhanced scrollbar and viewport synchronization for improved scrolling behavior and consistency.
-
Refactor
- Updated internal scrolling logic to use notification-driven updates and anchor-based viewport tracking for more reliable scroll position management.
-
Tests
- Added comprehensive test coverage for viewport synchronization behavior.