From 1320fcf5ce10ce0b8ac0e2f3580ae3adf1da18cc Mon Sep 17 00:00:00 2001 From: Kieran Klukas Date: Thu, 21 May 2026 15:22:23 -0400 Subject: [PATCH] fix(ui): scroll to the properly select model --- internal/ui/dialog/models.go | 6 +++++- internal/ui/dialog/models_list.go | 15 ++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/ui/dialog/models.go b/internal/ui/dialog/models.go index b06c62662c27fcd5d79a95618bc988b9a9b57468..215006577026285760fe875319546306a029dee1 100644 --- a/internal/ui/dialog/models.go +++ b/internal/ui/dialog/models.go @@ -496,7 +496,11 @@ func (m *Models) setProviderItems() error { // Set model groups in the list. m.list.SetGroups(groups...) m.list.SetSelectedItem(selectedItemID) - m.list.ScrollToTop() + if selectedItemID != "" { + m.list.ScrollToSelected() + } else { + m.list.ScrollToTop() + } // Update placeholder based on model type if !m.isOnboarding { diff --git a/internal/ui/dialog/models_list.go b/internal/ui/dialog/models_list.go index cec75c8e882c2db635a50ac3aa8839caa9a17601..735e36cff9ed7699614bd40b6f94ae9ac91a15ee 100644 --- a/internal/ui/dialog/models_list.go +++ b/internal/ui/dialog/models_list.go @@ -85,18 +85,15 @@ func (f *ModelsList) SetSelected(index int) { // SetSelectedItem sets the selected item in the list by item ID. func (f *ModelsList) SetSelectedItem(itemID string) { if itemID == "" { - f.SetSelected(0) return } - count := 0 - for _, g := range f.groups { - for _, item := range g.Items { - if item.ID() == itemID { - f.SetSelected(count) - return - } - count++ + // Walk the selectable model items using the same helpers that + // keyboard navigation uses, so we stay in sync with the flat + // list layout. + for ok := f.SelectFirst(); ok; ok = f.SelectNext() { + if mi, is := f.SelectedItem().(*ModelItem); is && mi.ID() == itemID { + return } } }