Fix UI lock when scrolling up during streaming output - #24
Merged
Conversation
Reported symptom: scrolling up while the agent streams responses makes the UI 'stuck at wherever you scrolled up', especially when mouse- selecting text — the selection rectangle drifts away from the cursor as new content arrives. Root cause: scroll_offset is 'lines from the bottom edge', a fixed quantity. As streaming tokens push new lines into the buffer, total grows but scroll_offset stays the same, so render_viewport's computed start = total - scroll_offset - visible drifts forward. The user's view silently follows the bottom at the fixed offset instead of staying on the absolute content they scrolled to. Selection indices are absolute (correct), but the highlighted rows drift along with the viewport so mouse-drags select the wrong lines. Fix: when content is appended to the buffer while scroll_offset > 0, bump scroll_offset by the number of lines added (clamped to max_offset). This keeps start anchored to the same absolute index. When scroll_offset == 0 the view continues to follow the bottom — that path is unchanged. Routes all buffer.push calls in commit_partial / write_line / write through a new private push_buffer_line helper. replace_from (used by the streaming-token markdown re-render) shifts scroll_offset by the size delta to preserve the anchor across rewrites. 6 new tests covering: - view stays anchored through 8 token appends while scrolled up - replace_from preserves anchor on both grow and shrink rewrites - bottom-anchored view (scroll_offset == 0) still follows new content - selection indices remain absolute under streaming appends - push_buffer_line clamps scroll_offset to max for tiny buffers - commit_partial routes through the anchor-aware push path
yogthos
force-pushed
the
fix/scroll-anchor-during-stream
branch
from
May 19, 2026 20:47
b86b819 to
84a23a6
Compare
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.
Reported symptom
Scrolling up while the agent streams responses makes the UI "stuck at wherever you scrolled up," especially when mouse-selecting text — the selection rectangle drifts away from the cursor as new content arrives.
Root cause
`scroll_offset` is "lines from the bottom edge," a fixed quantity. The viewport start is computed as:
```rust
start = total - scroll_offset - visible
```
As streaming tokens push new lines into the buffer, `total` grows but `scroll_offset` stays the same → `start` drifts forward. The user's view silently follows the bottom at the fixed offset instead of staying on the absolute content they scrolled to. Selection indices are absolute (correct), but the highlighted rows drift along with the viewport, so mouse-drags select the wrong lines.
Fix
When content is appended to the buffer while `scroll_offset > 0`, bump `scroll_offset` by the number of lines added (clamped to `max_offset`). This keeps `start` anchored to the same absolute index. When `scroll_offset == 0` the view continues to follow the bottom — that path is unchanged.
Test coverage (6 new tests)
Test plan