on main help sign in
feat(ui): invalidate rendered items on focus/blur
commit8d7e64fef8dbfdf31aa5bfa8831d7f1b114457e2 authorAyman Bagabas <ayman.bagabas@gmail.com> dateTue 9 Dec 2025, 11:04 (1 year ago) parent94de6bc
1 file changed+21
internal/ui/lazylist/list.go+21
internal/ui/lazylist/list.go+21
@@ -102,6 +102,12 @@ func (l *List) getItem(idx int) renderedItem {
102102 return ri
103103}
104104
105+// invalidateItem invalidates the cached rendered content of the item at the
106+// given index.
107+func (l *List) invalidateItem(idx int) {
108+ delete(l.renderedItems, idx)
109+}
110+
105111// ScrollToIndex scrolls the list to the given item index.
106112func (l *List) ScrollToIndex(index int) {
107113 if index < 0 {
@@ -314,11 +320,26 @@ func (l *List) Focus() {
314320 if l.selectedIdx < 0 || l.selectedIdx > len(l.items)-1 {
315321 return
316322 }
323+
324+ item := l.items[l.selectedIdx]
325+ if focusable, ok := item.(Focusable); ok {
326+ focusable.Focus()
327+ l.invalidateItem(l.selectedIdx)
328+ }
317329}
318330
319331// Blur removes the focus state from the list.
320332func (l *List) Blur() {
321333 l.focused = false
334+ if l.selectedIdx < 0 || l.selectedIdx > len(l.items)-1 {
335+ return
336+ }
337+
338+ item := l.items[l.selectedIdx]
339+ if focusable, ok := item.(Focusable); ok {
340+ focusable.Blur()
341+ l.invalidateItem(l.selectedIdx)
342+ }
322343}
323344
324345// ScrollToTop scrolls the list to the top.