on main help sign in
fix(ui): make chat follow-scroll reliable when content grows (#3240)

fix(ui): make chat follow-scroll reliable when content grows

commit6437f0d78c72987f9c90b5257f22504326b19c78 authorKieran Klukas <me@dunkirk.sh> dateThu 2 Jul 2026, 15:18 (3 months ago) parentcbb6daa
1 file changed+13−5
internal/ui/model/chat.go+13−5
internal/ui/model/chat.go+13−5
@@ -465,7 +465,13 @@ func (m *Chat) ScrollToTop() tea.Cmd {
465465// ScrollBy scrolls the chat view by the given number of line deltas.
466466func (m *Chat) ScrollBy(lines int) tea.Cmd {
467467 m.list.ScrollBy(lines)
468− m.follow = lines > 0 && m.AtBottom() // Disable follow mode if user scrolls up
468+ if lines < 0 {
469+ // Scrolling up always disables follow mode.
470+ m.follow = false
471+ } else if m.AtBottom() {
472+ // Scrolling down re-enables follow when we reach the bottom.
473+ m.follow = true
474+ }
469475 return m.showScrollbar()
470476}
471477
@@ -700,10 +706,11 @@ func (m *Chat) MessageItem(id string) chat.MessageItem {
700706// ToggleExpandedSelectedItem expands the selected message item if it is expandable.
701707func (m *Chat) ToggleExpandedSelectedItem() {
702708 if expandable, ok := m.list.SelectedItem().(chat.Expandable); ok {
709+ wasFollowing := m.follow
703710 if !expandable.ToggleExpanded() {
704711 m.ScrollToIndex(m.list.Selected())
705712 }
706− if m.AtBottom() {
713+ if wasFollowing {
707714 m.ScrollToBottom()
708715 }
709716 }
@@ -830,14 +837,15 @@ func (m *Chat) HandleDelayedClick(msg DelayedClickMsg) bool {
830837 // toggling expansion for clicks outside the clickable area.
831838 if handled {
832839 if expandable, ok := selectedItem.(chat.Expandable); ok {
840+ wasFollowing := m.follow
833841 if !expandable.ToggleExpanded() {
834842 m.ScrollToIndex(m.list.Selected())
835843 }
844+ if wasFollowing {
845+ m.ScrollToBottom()
846+ }
836847 }
837848 }
838− if m.AtBottom() {
839− m.ScrollToBottom()
840− }
841849 return handled
842850 }
843851