mirror of
https://github.com/charmbracelet/crush.git
synced 2025-08-02 05:20:46 +03:00
Merge remote-tracking branch 'origin/list' into tool_improvements
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
[38;2;223;219;221m│Item 29[m
|
||||
[38;2;223;219;221m│Item 29[m
|
||||
[38;2;223;219;221m│Item 29[m
|
||||
[38;2;223;219;221m│Item 29[m
|
||||
[38;2;223;219;221m│Item 29[m
|
||||
[38;2;223;219;221m│Item 29[m
|
||||
[38;2;223;219;221m│Item 29[m
|
||||
[38;2;223;219;221m│Item 29[m
|
||||
[38;2;223;219;221m│Item 29[m
|
||||
[38;2;223;219;221mTesting [m
|
||||
[38;2;223;219;221mItem 29[m
|
||||
[38;2;223;219;221mItem 29[m
|
||||
[38;2;223;219;221mItem 29[m
|
||||
[38;2;223;219;221mItem 29[m
|
||||
[38;2;223;219;221mItem 29[m
|
||||
[38;2;223;219;221mItem 29[m
|
||||
[38;2;223;219;221mItem 29[m
|
||||
[38;2;223;219;221mItem 29[m
|
||||
[38;2;223;219;221mItem 29[m
|
||||
[38;2;223;219;221m│Testing [m
|
||||
@@ -1,5 +1,5 @@
|
||||
[38;2;223;219;221mTesting [m
|
||||
[38;2;223;219;221m│Item 0[m
|
||||
[38;2;223;219;221m│Testing [m
|
||||
[38;2;223;219;221mItem 0[m
|
||||
[38;2;223;219;221mItem 1[m
|
||||
[38;2;223;219;221mItem 1[m
|
||||
[38;2;223;219;221mItem 2[m
|
||||
|
||||
Reference in New Issue
Block a user