Skip to content

perf: stick-to-bottom chat scroll - #19

Merged
SergKam merged 1 commit into
mainfrom
perf/chat-stick-to-bottom
Jun 11, 2026
Merged

perf: stick-to-bottom chat scroll#19
SergKam merged 1 commit into
mainfrom
perf/chat-stick-to-bottom

Conversation

@SergKam

@SergKam SergKam commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Problem

The chat scrolled to the bottom on every appended message. Useful normally, but it made it impossible to scroll up and read earlier messages while the agent was actively streaming — each delta yanked the view back to the tail.

Fix

Auto-follow the bottom only when the user is already there. A JS `stickToBottom` flag is updated from the window scroll position:

  • Within ~3 lines of the end → still "following", keep auto-scrolling.
  • User scrolls further up → stop auto-scrolling; leave them to read.
  • User scrolls back to the bottom → following resumes automatically.

The two modes are distinguished automatically from scroll position — no toggle, no button.

Submitting a message is an explicit "I'm engaging again" signal, so it re-engages follow and jumps to the bottom (new `force_scroll` flag on `append_user_message`), ensuring a scrolled-up user still sees their own message and the reply. History replay passes `false` so loading a tab doesn't yank a reader who scrolled up mid-load.

Scope

  • `src/chat_webview.rs` — `stickToBottom` flag + passive scroll listener; `scrollToBottom()` now gated; new `forceScrollToBottom()`; `force` param on `appendUserMsg`; `force_scroll` on `append_user_message`.
  • `src/ui/agent_panel/mod.rs` — live submit passes `true`.
  • `src/ui/agent_panel/chat_factory.rs` — history replay passes `false`.

All other scroll call sites (streaming deltas, tool calls, system messages) inherit the behavior unchanged through the gated `scrollToBottom()`.

Checks

fmt ✅ · clippy `-D warnings` (lib+bins) ✅ · tests ✅

The chat auto-scrolled to the bottom on every appended message, so reading
earlier history while the agent was actively streaming was impossible — each
delta yanked the view back down.

Track a JS 'stickToBottom' flag from the window scroll position: auto-scroll
only while the user is following the tail (within ~3 lines of the end), and
stop the instant they scroll up. Following resumes automatically when they
scroll back down. Submitting a message re-engages follow and jumps to the
bottom (via a new force_scroll flag on append_user_message), so a scrolled-up
user still sees their own message and the reply; history replay passes false.
@SergKam
SergKam merged commit e72998a into main Jun 11, 2026
2 checks passed
@SergKam
SergKam deleted the perf/chat-stick-to-bottom branch June 11, 2026 01:00
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.

1 participant