@@ -275,25 +275,38 @@ func (m *AppModel) handleSpaceKey() (tea.Model, tea.Cmd) {
275275 logging .DebugLogger .Printf ("Toggling selection for model: %s (before: %v)\n " , item .Name , item .Selected )
276276 item .Selected = ! item .Selected
277277
278- // Update the item in the list's items
279- items := m .list .Items ()
280- for i , listItem := range items {
278+ // Update both the filtered and unfiltered lists
279+ filteredItems := m .list .Items ()
280+ for i , listItem := range filteredItems {
281281 if model , ok := listItem .(Model ); ok && model .Name == item .Name {
282- items [i ] = item
283- break
282+ filteredItems [i ] = item
284283 }
285284 }
286285
287- m .list .SetItems (items )
288-
289- // Find the index of the actual item in the full list and update it
286+ // Always update the main model list
290287 for i , model := range m .models {
291288 if model .Name == item .Name {
292289 m .models [i ] = item
293- break
294290 }
295291 }
296292
293+ // Update the items in the list
294+ m .list .SetItems (filteredItems )
295+
296+ // If filtering is active, force a refresh of the view
297+ if m .list .FilterState () == list .Filtering || m .list .FilterState () == list .FilterApplied {
298+ // Store current cursor position
299+ currentIndex := m .list .Index ()
300+
301+ // Force a view refresh by temporarily clearing and reapplying items
302+ tempItems := m .list .Items ()
303+ m .list .SetItems (nil )
304+ m .list .SetItems (tempItems )
305+
306+ // Restore cursor position
307+ m .list .Select (currentIndex )
308+ }
309+
297310 logging .DebugLogger .Printf ("Toggled selection for model: %s (after: %v)\n " , item .Name , item .Selected )
298311 }
299312 return m , nil
0 commit comments