on main help sign in
fix(ui): scroll to the properly select model
1320fcfKieran Klukas
internal/ui/dialog/models.go+5−1
@@ -496,7 +496,11 @@ func (m *Models) setProviderItems() error {
496 // Set model groups in the list.
496 // Set model groups in the list.
497 m.list.SetGroups(groups...)
497 m.list.SetGroups(groups...)
498 m.list.SetSelectedItem(selectedItemID)
498 m.list.SetSelectedItem(selectedItemID)
499+ if selectedItemID != "" {
500+ m.list.ScrollToSelected()
501+ } else {
499− m.list.ScrollToTop()
502+ m.list.ScrollToTop()
503+ }
500
504
501 // Update placeholder based on model type
505 // Update placeholder based on model type
502 if !m.isOnboarding {
506 if !m.isOnboarding {
internal/ui/dialog/models_list.go+6−9
@@ -85,18 +85,15 @@ func (f *ModelsList) SetSelected(index int) {
85// SetSelectedItem sets the selected item in the list by item ID.
85// SetSelectedItem sets the selected item in the list by item ID.
86func (f *ModelsList) SetSelectedItem(itemID string) {
86func (f *ModelsList) SetSelectedItem(itemID string) {
87 if itemID == "" {
87 if itemID == "" {
88− f.SetSelected(0)
89 return
88 return
90 }
89 }
91
90
92− count := 0
91+ // Walk the selectable model items using the same helpers that
93− for _, g := range f.groups {
92+ // keyboard navigation uses, so we stay in sync with the flat
94− for _, item := range g.Items {
93+ // list layout.
95− if item.ID() == itemID {
94+ for ok := f.SelectFirst(); ok; ok = f.SelectNext() {
96− f.SetSelected(count)
95+ if mi, is := f.SelectedItem().(*ModelItem); is && mi.ID() == itemID {
97− return
96+ return
98− }
99− count++
100 }
97 }
101 }
98 }
102}
99}