From 3bda767c6700db1ead64af01471b3e7b868a569f Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 4 Feb 2026 14:53:24 +0300 Subject: [PATCH] fix(ui): ensure we anchor the chat view to the bottom when toggling (#2117) an item at the bottom of the chat When toggling an item in the chat, if that item is at the bottom of the chat, we want to ensure that we stay anchored to the bottom. This prevents a gap from appearing at the bottom of the chat when toggling an item that is currently selected and at the bottom. --- internal/ui/list/list.go | 2 +- internal/ui/model/chat.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/ui/list/list.go b/internal/ui/list/list.go index 33a5087c9ceae3f03bb2c8f78b2cc8089f87057c..c3693494881c0a600f3d519471835789ebd54530 100644 --- a/internal/ui/list/list.go +++ b/internal/ui/list/list.go @@ -79,7 +79,7 @@ func (l *List) Gap() int { func (l *List) AtBottom() bool { const margin = 2 - if len(l.items) == 0 { + if len(l.items) == 0 || l.offsetIdx >= len(l.items)-1 { return true } diff --git a/internal/ui/model/chat.go b/internal/ui/model/chat.go index 723e97fb76c04d75922a5aec60d9afa970e41d97..8deb2c3992e249b7baa78ca693f88beaf44ae5d4 100644 --- a/internal/ui/model/chat.go +++ b/internal/ui/model/chat.go @@ -439,6 +439,9 @@ func (m *Chat) ToggleExpandedSelectedItem() { if expandable, ok := m.list.SelectedItem().(chat.Expandable); ok { expandable.ToggleExpanded() m.list.ScrollToIndex(m.list.Selected()) + if m.list.AtBottom() { + m.list.ScrollToBottom() + } } } @@ -547,6 +550,9 @@ func (m *Chat) HandleDelayedClick(msg DelayedClickMsg) bool { expandable.ToggleExpanded() } m.list.ScrollToIndex(m.list.Selected()) + if m.list.AtBottom() { + m.list.ScrollToBottom() + } return handled }