Skip to content

fix: remember and restore scroll position per session#71

Merged
rusty4444 merged 1 commit into
rusty4444:mainfrom
grunjol:feat/scroll-position
Jul 7, 2026
Merged

fix: remember and restore scroll position per session#71
rusty4444 merged 1 commit into
rusty4444:mainfrom
grunjol:feat/scroll-position

Conversation

@grunjol

@grunjol grunjol commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

When leaving and re-entering a chat session, the scroll position is
now restored to where the user was, instead of always jumping to the
bottom (or top, since _scrollToBottom() fired before the ListView
was laid out).

Changes

_lastPixels — tracks the last known scroll position, updated in
_onScroll() on every scroll event. Storing in dispose() was
unreliable because hasClients is already false when the widget tree
tears down.

_savedPositions — a static map (sessionId → pixels) shared
across ChatScreen instances so returning to the same session
restores the previous scroll offset.

_fetchMessages() — if a saved position exists for the session,
uses WidgetsBinding.instance.addPostFrameCallback to jumpTo() the
saved offset after layout completes. On first visit, scrolls to the
bottom as before.

@rusty4444 rusty4444 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hermes Agent Automated Review — PR #71

Verdict: APPROVE

Summary

Remembers and restores scroll position per session. Saves last scroll position before dispose, restores it on session load with proper bounds clamping.

✅ Looks Good

  • Per-session scroll position storage prevents losing reading context when switching sessions
  • clamp(0.0, maxScrollExtent) prevents out-of-bounds scroll errors
  • Falls back to scroll-to-bottom for new sessions (no saved position)
  • Proper hasClients checks before accessing scroll controller

💡 Suggestions (non-blocking)

  • The scroll restore logic is duplicated in _loadMessages and _sendMessage completion — consider extracting to a helper method _restoreScrollPosition()

Reviewed by Hermes Agent — July 8, 2026

@rusty4444 rusty4444 merged commit 978ba75 into rusty4444:main Jul 7, 2026
1 check passed
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.

2 participants