fix(tui): prevent scroll snap when reading history during LLM response#29095
Open
divitkashyap wants to merge 1 commit into
Open
fix(tui): prevent scroll snap when reading history during LLM response#29095divitkashyap wants to merge 1 commit into
divitkashyap wants to merge 1 commit into
Conversation
Track when the user has scrolled away from the bottom and disable sticky scroll while that's true. Without this, every token streamed during an LLM response snaps the viewport back to the bottom, making it impossible to read history mid-response. Upward scroll commands (Page Up, Line Up, Half Page Up, First message) set the flag. Commands that return to bottom (Last message, toBottom, session sync) reset it. Closes anomalyco#4196
|
Thanks @divitkashyap 🙏🏼 |
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.
Issue for this PR
Closes #29094 (re-open of #4196)
Type of change
What does this PR do?
The session message scrollbox is hard-coded to `stickyScroll={true}`, so every streamed token pulls the viewport back to the bottom. Users can't read older messages while an LLM response is in flight.
Track when the user has scrolled away from the bottom in a `userScrolledUp` signal and make `stickyScroll` reactive on `!userScrolledUp()`. Upward commands (Page Up, Line Up, Half Page Up, First message) set the flag; commands that return to bottom (Last message, `toBottom()`, session sync) clear it.
Mirrors the pattern already used in the web client's `packages/ui/src/hooks/create-auto-scroll.tsx`.
How did you verify your code works?
Manual test against the steps in the linked issue: scroll up mid-response, viewport stays put; press Last Message or scroll to bottom, sticky resumes. Diff is contained to `packages/opencode/src/cli/cmd/tui/routes/session/index.tsx`.
Checklist
This supersedes my earlier PR #21343, which was auto-closed by cleanup. Rebased onto current `dev`.