Skip to content

fix(tui): prevent scroll snap when reading history during LLM response#29095

Open
divitkashyap wants to merge 1 commit into
anomalyco:devfrom
divitkashyap:fix/tui-scroll-snap-4196
Open

fix(tui): prevent scroll snap when reading history during LLM response#29095
divitkashyap wants to merge 1 commit into
anomalyco:devfrom
divitkashyap:fix/tui-scroll-snap-4196

Conversation

@divitkashyap
Copy link
Copy Markdown

Issue for this PR

Closes #29094 (re-open of #4196)

Type of change

  • Bug fix

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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

This supersedes my earlier PR #21343, which was auto-closed by cleanup. Rebased onto current `dev`.

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
@david-alvarez-rosa
Copy link
Copy Markdown

Thanks @divitkashyap 🙏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reading chat history during LLM responses still re-snaps the viewport (re-open of #4196)

2 participants