chore: small fix

Kujtim Hoxha created

Change summary

internal/tui/exp/list/list.go                                                                                                                          | 17 
internal/tui/exp/list/testdata/TestListMovement/should_not_change_offset_when_new_items_are_appended_and_we_are_at_the_bottom_in_backwards_list.golden | 20 
internal/tui/exp/list/testdata/TestListMovement/should_not_change_offset_when_new_items_are_prepended_and_we_are_at_the_top_in_forward_list.golden     |  4 
3 files changed, 15 insertions(+), 26 deletions(-)

Detailed changes

internal/tui/exp/list/list.go 🔗

@@ -746,20 +746,16 @@ func (l *list[T]) GetSize() (int, int) {
 
 // GoToBottom implements List.
 func (l *list[T]) GoToBottom() tea.Cmd {
-	if l.offset != 0 {
-		l.selectedItem = ""
-	}
 	l.offset = 0
+	l.selectedItem = ""
 	l.direction = DirectionBackward
 	return l.render()
 }
 
 // GoToTop implements List.
 func (l *list[T]) GoToTop() tea.Cmd {
-	if l.offset != 0 {
-		l.selectedItem = ""
-	}
 	l.offset = 0
+	l.selectedItem = ""
 	l.direction = DirectionForward
 	return l.render()
 }
@@ -996,14 +992,7 @@ func (l *list[T]) UpdateItem(id string, item T) tea.Cmd {
 		if hasOldItem && l.direction == DirectionBackward {
 			// if we are the last item and there is no offset
 			// make sure to go to the bottom
-			if inx == l.items.Len()-1 && l.offset == 0 {
-				cmd = l.GoToBottom()
-				if cmd != nil {
-					cmds = append(cmds, cmd)
-				}
-
-				// if the item is at least partially below the viewport
-			} else if oldPosition < oldItem.end {
+			if oldPosition < oldItem.end {
 				newItem, ok := l.renderedItems.Get(item.ID())
 				if ok {
 					newLines := newItem.height - oldItem.height

internal/tui/exp/list/testdata/TestListMovement/should_not_change_offset_when_new_items_are_appended_and_we_are_at_the_bottom_in_backwards_list.golden 🔗

@@ -1,10 +1,10 @@
-│Item 29  
-│Item 29  
-│Item 29  
-│Item 29  
-│Item 29  
-│Item 29  
-│Item 29  
-│Item 29  
-│Item 29  
-Testing   
+Item 29   
+Item 29   
+Item 29   
+Item 29   
+Item 29   
+Item 29   
+Item 29   
+Item 29   
+Item 29   
+│Testing