Skip to content

fix - chat not scrolling to the newest messages in long conversations#334

Merged
jdneo merged 2 commits into
mainfrom
tori/chatview
Jul 3, 2026
Merged

fix - chat not scrolling to the newest messages in long conversations#334
jdneo merged 2 commits into
mainfrom
tori/chatview

Conversation

@xinyi-gong

Copy link
Copy Markdown
Member

Summary

Fixes #63. In long conversations the chat could no longer be scrolled down
to the latest messages: the scrollbar looked scrolled to the bottom (or kept
moving) but the content stopped, leaving the newest turns unreachable.

Root cause

ChatContentViewer extended ScrolledComposite, which scrolls by moving a
single content child whose height equals the entire conversation. On Windows
a native child window position is a signed 16-bit value, so once the required
offset exceeded that range the OS clamped it — the content could not move
further and the bottom became unreachable. This matches every reported
symptom: only long sessions, Windows only, and "maximize the view" or
"Ctrl+-" (which shrink the total pixel height) working around it.

Fix

Rewrite ChatContentViewer as a self-managed, windowed vertical scroller
(extends Composite with SWT.V_SCROLL):

  • cmpContent is pinned to the viewport rectangle and never grown or moved.
  • A 32-bit logical model (scrollOffset / totalHeight / per-turn tops)
    drives scrolling; each turn is positioned at y = top - scrollOffset.
  • Turns intersecting the viewport are laid out; the rest are parked with
    setVisible(false), so no native child ever receives an out-of-range
    coordinate.

Behavior preserved from the previous implementation:

  • Auto-scroll: scrolling away from the bottom pauses follow-the-tail
    during streaming; scrolling back to the bottom resumes it.
  • Latest user turn pinned to the top: reserved via virtual bottom
    padding, which also keeps "scroll to bottom" aligned with the real maximum
    so auto-scroll stays correct for both short and long rounds.
  • Streaming stays cheap: incremental passes re-measure only the trailing
    (mutating) turns; sealed turns keep cached heights.

Scroll step now derives from the OS-provided wheel line count (event.count)
times the font line height, so it follows the user's system scroll settings
and DPI instead of a fixed pixel constant.

Copilot AI review requested due to automatic review settings July 2, 2026 05:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Windows-only scrolling failure in long chat conversations by replacing ScrolledComposite-based scrolling (which can hit native coordinate limits) with a self-managed, windowed vertical scroller in ChatContentViewer.

Changes:

  • Reworked ChatContentViewer to extends Composite with a logical scroll model (scrollOffset, totalHeight) and manual child positioning.
  • Added windowing + measurement caching (IdentityHashMap height cache) to avoid remeasuring sealed turns and to keep off-viewport turns hidden.
  • Implemented explicit mouse wheel scrolling and scrollbar synchronization for the manual layout approach.

@jdneo jdneo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jdneo jdneo merged commit 073b82a into main Jul 3, 2026
4 checks passed
@jdneo jdneo deleted the tori/chatview branch July 3, 2026 05:17
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.

At some point not possible to scroll chat down to see last messages

3 participants