Smart scroll for the agent terminal#94
Merged
Merged
Conversation
Streaming pty output yanked the user back to the bottom on every write because xterm follows the cursor. Snapshot the user's distance from the bottom before each write and restore it in the post-parse callback so they can read past output while the agent keeps streaming. Returning to the bottom re-engages auto-follow. Detection runs against the live .xterm-viewport scrollTop — the only source of truth that updates synchronously with user input. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
term.write. The terminal now snapshots the user's distance from the bottom before each write and restores it in the post-parse callback, so past output stays readable while the agent streams..xterm-viewportscrollTop(the only source of truth that updates synchronously with user input —term.onScrolllags becausebuffer.viewportYsyncs from the DOM async).Implementation
src/renderer/components/terminal/smartScroll.tswith pure decision functions (isDomAnchored,distanceFromBottom,computeDomScrollAction, plus buffer-space equivalents kept for symmetry/tests) and aattachSmartScroll(term, getVisible)controller exposingwrite/isAnchored/dispose.useTerminal.tsnow routes pty data throughcontroller.writeinstead ofterm.write, drops the oldanchoredToBottominstance field, and asks the controller for the anchor state in the visibility re-fit effect.Test plan
tests/unit/components/terminal/smartScroll.test.ts)attachSmartScrollagainst a fake terminal that simulates xterm's auto-follow on writes (tests/unit/components/terminal/smartScroll.integration.test.ts)tests/e2e/smart-scroll.spec.ts):Note on screenshots
This is a streaming-time scroll behaviour change — a static screenshot can't show it. The Playwright e2e suite is the canonical demo; it asserts the exact pixel-level behaviour against a real browser running the app.
🤖 Generated with Claude Code