From 8d7e64fef8dbfdf31aa5bfa8831d7f1b114457e2 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 9 Dec 2025 11:04:09 -0500 Subject: [PATCH] feat(ui): invalidate rendered items on focus/blur --- internal/ui/lazylist/list.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/ui/lazylist/list.go b/internal/ui/lazylist/list.go index 334af80b263b5e64e3cf8cecad36ca410f47f71c..8e81d96914130d5a8eebdf5ca5dd6d4ba5fb3e8d 100644 --- a/internal/ui/lazylist/list.go +++ b/internal/ui/lazylist/list.go @@ -102,6 +102,12 @@ func (l *List) getItem(idx int) renderedItem { return ri } +// invalidateItem invalidates the cached rendered content of the item at the +// given index. +func (l *List) invalidateItem(idx int) { + delete(l.renderedItems, idx) +} + // ScrollToIndex scrolls the list to the given item index. func (l *List) ScrollToIndex(index int) { if index < 0 { @@ -314,11 +320,26 @@ func (l *List) Focus() { if l.selectedIdx < 0 || l.selectedIdx > len(l.items)-1 { return } + + item := l.items[l.selectedIdx] + if focusable, ok := item.(Focusable); ok { + focusable.Focus() + l.invalidateItem(l.selectedIdx) + } } // Blur removes the focus state from the list. func (l *List) Blur() { l.focused = false + if l.selectedIdx < 0 || l.selectedIdx > len(l.items)-1 { + return + } + + item := l.items[l.selectedIdx] + if focusable, ok := item.(Focusable); ok { + focusable.Blur() + l.invalidateItem(l.selectedIdx) + } } // ScrollToTop scrolls the list to the top.