diff --git a/internal/csync/slices.go b/internal/csync/slices.go index 4e67ac1a127f577d1d13673e4311b2ea44e17393..ba47062b51de1a038836467f15bd4e9672ab3303 100644 --- a/internal/csync/slices.go +++ b/internal/csync/slices.go @@ -149,8 +149,8 @@ func (s *Slice[T]) Seq() iter.Seq[T] { } } -// SeqWithIndex returns an iterator that yields index-value pairs from the slice. -func (s *Slice[T]) SeqWithIndex() iter.Seq2[int, T] { +// Seq2 returns an iterator that yields index-value pairs from the slice. +func (s *Slice[T]) Seq2() iter.Seq2[int, T] { // Take a snapshot to avoid holding the lock during iteration items := s.Slice() return func(yield func(int, T) bool) { diff --git a/internal/csync/slices_test.go b/internal/csync/slices_test.go index fd1bd69ba6ca4d07cd5383cb52746e41caa8d901..d86b02537fe0534ed60de0e314e1e1d9b7b866b6 100644 --- a/internal/csync/slices_test.go +++ b/internal/csync/slices_test.go @@ -250,7 +250,7 @@ func TestSlice(t *testing.T) { var indices []int var values []string - for i, v := range s.SeqWithIndex() { + for i, v := range s.Seq2() { indices = append(indices, i) values = append(values, v) } diff --git a/internal/tui/exp/list/list.go b/internal/tui/exp/list/list.go index 1970abb3ea925715fe01d74358d0e89c1a637fb7..3af90d405382ba5df207774c4f2fba109717034a 100644 --- a/internal/tui/exp/list/list.go +++ b/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 diff --git a/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 b/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 index 9166c3d388f45243860fde6827b42196305d84ea..8cea66d71fb8e43fc9e0ac8fcb6ee1000cfcb5e4 100644 --- a/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 +++ b/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  \ No newline at end of file +Item 29 +Item 29 +Item 29 +Item 29 +Item 29 +Item 29 +Item 29 +Item 29 +Item 29 +│Testing  \ No newline at end of file diff --git a/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 b/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 index 5493247c7713c227dc5a46ea5422c2b8c10a492e..faed253a104304630e9e33decc445622cde8739a 100644 --- a/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 +++ b/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 @@ -1,5 +1,5 @@ -Testing  -│Item 0 +│Testing  +Item 0 Item 1 Item 1 Item 2