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
}
Ayman Bagabas created
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(-)
@@ -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
}
@@ -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
}