Skip to content

Commit 3640af3

Browse files
committed
Fixed widgetlist focus loss
1 parent 9806f51 commit 3640af3

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

widget/widgetlist/widgetlist.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,6 @@ func (w *Widget[T]) removeItem(index int) {
713713
}
714714

715715
func (w *Widget[T]) FocusFirst() {
716-
w.focusManager.FocusFirst()
717-
718716
if w.filterState == FilterApplied {
719717
if len(w.filteredListItems) > 0 {
720718
w.globalIndex = w.filteredListItems[0].Index
@@ -729,6 +727,16 @@ func (w *Widget[T]) FocusFirst() {
729727
w.globalIndex = 0
730728
}
731729

730+
// Focus the cursor's global index directly. Filtering does not deactivate
731+
// the filtered-out items, so focusManager.FocusFirst would land on the
732+
// first item of the full list instead of the first filtered match, leaving
733+
// the focused style desynced from the cursor.
734+
if w.globalIndex >= 0 {
735+
w.focusManager.Focus(w.globalIndex)
736+
} else {
737+
w.focusManager.BlurCurrent()
738+
}
739+
732740
w.moveCursor(w.globalIndex)
733741
}
734742

0 commit comments

Comments
 (0)