fix(ui): only scroll to selected item if item collapsed

Ayman Bagabas created

Change summary

internal/ui/model/chat.go | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

Detailed changes

internal/ui/model/chat.go 🔗

@@ -437,8 +437,9 @@ func (m *Chat) MessageItem(id string) chat.MessageItem {
 // ToggleExpandedSelectedItem expands the selected message item if it is expandable.
 func (m *Chat) ToggleExpandedSelectedItem() {
 	if expandable, ok := m.list.SelectedItem().(chat.Expandable); ok {
-		expandable.ToggleExpanded()
-		m.list.ScrollToIndex(m.list.Selected())
+		if !expandable.ToggleExpanded() {
+			m.list.ScrollToIndex(m.list.Selected())
+		}
 		if m.list.AtBottom() {
 			m.list.ScrollToBottom()
 		}
@@ -547,9 +548,10 @@ func (m *Chat) HandleDelayedClick(msg DelayedClickMsg) bool {
 		handled := clickable.HandleMouseClick(ansi.MouseButton1, msg.X, msg.Y)
 		// Toggle expansion if applicable.
 		if expandable, ok := selectedItem.(chat.Expandable); ok {
-			expandable.ToggleExpanded()
+			if !expandable.ToggleExpanded() {
+				m.list.ScrollToIndex(m.list.Selected())
+			}
 		}
-		m.list.ScrollToIndex(m.list.Selected())
 		if m.list.AtBottom() {
 			m.list.ScrollToBottom()
 		}