@@ -85,18 +85,15 @@ func (f *ModelsList) SetSelected(index int) {
8585// SetSelectedItem sets the selected item in the list by item ID.
8686func (f *ModelsList) SetSelectedItem(itemID string) {
8787 if itemID == "" {
88− f.SetSelected(0)
8988 return
9089 }
9190
92− count := 0
93− for _, g := range f.groups {
94− for _, item := range g.Items {
95− if item.ID() == itemID {
96− f.SetSelected(count)
97− return
98− }
99− count++
91+ // Walk the selectable model items using the same helpers that
92+ // keyboard navigation uses, so we stay in sync with the flat
93+ // list layout.
94+ for ok := f.SelectFirst(); ok; ok = f.SelectNext() {
95+ if mi, is := f.SelectedItem().(*ModelItem); is && mi.ID() == itemID {
96+ return
10097 }
10198 }
10299}