on main help sign in
Merge remote-tracking branch 'origin/list' into tool_improvements
f8aa4bfKujtim Hoxha
internal/csync/slices.go+2−2
@@ -149,8 +149,8 @@ func (s *Slice[T]) Seq() iter.Seq[T] {
149 }
149 }
150}
150}
151
151
152−// SeqWithIndex returns an iterator that yields index-value pairs from the slice.
152+// Seq2 returns an iterator that yields index-value pairs from the slice.
153−func (s *Slice[T]) SeqWithIndex() iter.Seq2[int, T] {
153+func (s *Slice[T]) Seq2() iter.Seq2[int, T] {
154 // Take a snapshot to avoid holding the lock during iteration
154 // Take a snapshot to avoid holding the lock during iteration
155 items := s.Slice()
155 items := s.Slice()
156 return func(yield func(int, T) bool) {
156 return func(yield func(int, T) bool) {
internal/csync/slices_test.go+1−1
@@ -250,7 +250,7 @@ func TestSlice(t *testing.T) {
250
250
251 var indices []int
251 var indices []int
252 var values []string
252 var values []string
253− for i, v := range s.SeqWithIndex() {
253+ for i, v := range s.Seq2() {
254 indices = append(indices, i)
254 indices = append(indices, i)
255 values = append(values, v)
255 values = append(values, v)
256 }
256 }
internal/tui/exp/list/list.go+3−14
@@ -746,20 +746,16 @@ func (l *list[T]) GetSize() (int, int) {
746
746
747// GoToBottom implements List.
747// GoToBottom implements List.
748func (l *list[T]) GoToBottom() tea.Cmd {
748func (l *list[T]) GoToBottom() tea.Cmd {
749− if l.offset != 0 {
750− l.selectedItem = ""
751− }
752 l.offset = 0
749 l.offset = 0
750+ l.selectedItem = ""
753 l.direction = DirectionBackward
751 l.direction = DirectionBackward
754 return l.render()
752 return l.render()
755}
753}
756
754
757// GoToTop implements List.
755// GoToTop implements List.
758func (l *list[T]) GoToTop() tea.Cmd {
756func (l *list[T]) GoToTop() tea.Cmd {
759− if l.offset != 0 {
760− l.selectedItem = ""
761− }
762 l.offset = 0
757 l.offset = 0
758+ l.selectedItem = ""
763 l.direction = DirectionForward
759 l.direction = DirectionForward
764 return l.render()
760 return l.render()
765}
761}
@@ -996,14 +992,7 @@ func (l *list[T]) UpdateItem(id string, item T) tea.Cmd {
996 if hasOldItem && l.direction == DirectionBackward {
992 if hasOldItem && l.direction == DirectionBackward {
997 // if we are the last item and there is no offset
993 // if we are the last item and there is no offset
998 // make sure to go to the bottom
994 // make sure to go to the bottom
999− if inx == l.items.Len()-1 && l.offset == 0 {
1000− cmd = l.GoToBottom()
1001− if cmd != nil {
1002− cmds = append(cmds, cmd)
1003− }
1004−
1005− // if the item is at least partially below the viewport
1006− } else if oldPosition < oldItem.end {
995+ if oldPosition < oldItem.end {
1007 newItem, ok := l.renderedItems.Get(item.ID())
996 newItem, ok := l.renderedItems.Get(item.ID())
1008 if ok {
997 if ok {
1009 newLines := newItem.height - oldItem.height
998 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+10−10
@@ -1,10 +1,10 @@
1−│Item 29
1+Item 29
2−│Item 29
2+Item 29
3−│Item 29
3+Item 29
4−│Item 29
4+Item 29
5−│Item 29
5+Item 29
6−│Item 29
6+Item 29
7−│Item 29
7+Item 29
8−│Item 29
8+Item 29
9−│Item 29
9+Item 29
10−Testing 
10+│Testing 
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+2−2
@@ -1,5 +1,5 @@
1−Testing 
1+│Testing 
2−│Item 0
2+Item 0
3Item 1
3Item 1
4Item 1
4Item 1
5Item 2
5Item 2