@@ -1,6 +1,7 @@
1package list
1package list
6 "github.com/charmbracelet/bubbles/v2/key"
7 "github.com/charmbracelet/bubbles/v2/key"
@@ -201,7 +202,7 @@ func (l *list[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
201 return l, nil
202 return l, nil
202 case anim.StepMsg:
203 case anim.StepMsg:
203 var cmds []tea.Cmd
204 var cmds []tea.Cmd
204− for _, item := range l.items.Slice() {
205+ for _, item := range slices.Collect(l.items.Seq()) {
205 if i, ok := any(item).(HasAnim); ok && i.Spinning() {
206 if i, ok := any(item).(HasAnim); ok && i.Spinning() {
206 updated, cmd := i.Update(msg)
207 updated, cmd := i.Update(msg)
207 cmds = append(cmds, cmd)
208 cmds = append(cmds, cmd)
@@ -288,7 +289,7 @@ func (l *list[T]) viewPosition() (int, int) {
289func (l *list[T]) recalculateItemPositions() {
290func (l *list[T]) recalculateItemPositions() {
290 currentContentHeight := 0
291 currentContentHeight := 0
291− for _, item := range l.items.Slice() {
292+ for _, item := range slices.Collect(l.items.Seq()) {
292 rItem, ok := l.renderedItems.Get(item.ID())
293 rItem, ok := l.renderedItems.Get(item.ID())
@@ -561,7 +562,7 @@ func (l *list[T]) focusSelectedItem() tea.Cmd {
561 return nil
562 return nil
563 var cmds []tea.Cmd
564 var cmds []tea.Cmd
564− for _, item := range l.items.Slice() {
565+ for _, item := range slices.Collect(l.items.Seq()) {
565 if f, ok := any(item).(layout.Focusable); ok {
566 if f, ok := any(item).(layout.Focusable); ok {
566 if item.ID() == l.selectedItem && !f.IsFocused() {
567 if item.ID() == l.selectedItem && !f.IsFocused() {
567 cmds = append(cmds, f.Focus())
568 cmds = append(cmds, f.Focus())
@@ -580,7 +581,7 @@ func (l *list[T]) blurSelectedItem() tea.Cmd {
580 return nil
581 return nil
582 var cmds []tea.Cmd
583 var cmds []tea.Cmd
583− for _, item := range l.items.Slice() {
584+ for _, item := range slices.Collect(l.items.Seq()) {
584 if f, ok := any(item).(layout.Focusable); ok {
585 if f, ok := any(item).(layout.Focusable); ok {
585 if item.ID() == l.selectedItem && f.IsFocused() {
586 if item.ID() == l.selectedItem && f.IsFocused() {
586 cmds = append(cmds, f.Blur())
587 cmds = append(cmds, f.Blur())
@@ -655,7 +656,7 @@ func (l *list[T]) AppendItem(item T) tea.Cmd {
656 l.items.Append(item)
657 l.items.Append(item)
657 l.indexMap = csync.NewMap[string, int]()
658 l.indexMap = csync.NewMap[string, int]()
658− for inx, item := range l.items.Slice() {
659+ for inx, item := range slices.Collect(l.items.Seq()) {
659 l.indexMap.Set(item.ID(), inx)
660 l.indexMap.Set(item.ID(), inx)
661 if l.width > 0 && l.height > 0 {
662 if l.width > 0 && l.height > 0 {
@@ -702,7 +703,7 @@ func (l *list[T]) DeleteItem(id string) tea.Cmd {
703 l.items.Delete(inx)
704 l.items.Delete(inx)
704 l.renderedItems.Del(id)
705 l.renderedItems.Del(id)
705− for inx, item := range l.items.Slice() {
706+ for inx, item := range slices.Collect(l.items.Seq()) {
706 l.indexMap.Set(item.ID(), inx)
707 l.indexMap.Set(item.ID(), inx)
@@ -767,7 +768,7 @@ func (l *list[T]) IsFocused() bool {
768// Items implements List.
769// Items implements List.
769func (l *list[T]) Items() []T {
770func (l *list[T]) Items() []T {
770− return l.items.Slice()
771+ return slices.Collect(l.items.Seq())
773func (l *list[T]) incrementOffset(n int) {
774func (l *list[T]) incrementOffset(n int) {
@@ -822,7 +823,7 @@ func (l *list[T]) PrependItem(item T) tea.Cmd {
823 l.items.Prepend(item)
824 l.items.Prepend(item)
824 l.indexMap = csync.NewMap[string, int]()
825 l.indexMap = csync.NewMap[string, int]()
825− for inx, item := range l.items.Slice() {
826+ for inx, item := range slices.Collect(l.items.Seq()) {
826 l.indexMap.Set(item.ID(), inx)
827 l.indexMap.Set(item.ID(), inx)
828 if l.width > 0 && l.height > 0 {
829 if l.width > 0 && l.height > 0 {
@@ -926,7 +927,7 @@ func (l *list[T]) SelectedItem() *T {
926func (l *list[T]) SetItems(items []T) tea.Cmd {
927func (l *list[T]) SetItems(items []T) tea.Cmd {
927 l.items.SetSlice(items)
928 l.items.SetSlice(items)
928 var cmds []tea.Cmd
929 var cmds []tea.Cmd
929− for inx, item := range l.items.Slice() {
930+ for inx, item := range slices.Collect(l.items.Seq()) {
930 if i, ok := any(item).(Indexable); ok {
931 if i, ok := any(item).(Indexable); ok {
931 i.SetIndex(inx)
932 i.SetIndex(inx)
@@ -949,7 +950,7 @@ func (l *list[T]) reset(selectedItem string) tea.Cmd {
949 l.selectedItem = selectedItem
950 l.selectedItem = selectedItem
950 l.indexMap = csync.NewMap[string, int]()
951 l.indexMap = csync.NewMap[string, int]()
951 l.renderedItems = csync.NewMap[string, renderedItem]()
952 l.renderedItems = csync.NewMap[string, renderedItem]()
952− for inx, item := range l.items.Slice() {
953+ for inx, item := range slices.Collect(l.items.Seq()) {
953 l.indexMap.Set(item.ID(), inx)
954 l.indexMap.Set(item.ID(), inx)
954 if l.width > 0 && l.height > 0 {
955 if l.width > 0 && l.height > 0 {
955 cmds = append(cmds, item.SetSize(l.width, l.height))
956 cmds = append(cmds, item.SetSize(l.width, l.height))