From 6033d5f6bcf33b47e0a2505c8636f5e7844dba8d Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Fri, 3 Nov 2023 17:24:37 -0700 Subject: [PATCH] fix search field action button not updating sometimes --- ui/widgets/searchentry.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ui/widgets/searchentry.go b/ui/widgets/searchentry.go index 33a6957..c26786b 100644 --- a/ui/widgets/searchentry.go +++ b/ui/widgets/searchentry.go @@ -28,16 +28,17 @@ func NewSearchEntry() *SearchEntry { debounceFunc := util.NewDebouncer(200*time.Millisecond, func() { sf.sendSearch(sf.Entry.Text) }) - sf.Entry.OnChanged = func(_ string) { debounceFunc() } + sf.Entry.OnChanged = func(_ string) { + if sf.updateActionButton() { + sf.ActionItem.Refresh() + } + debounceFunc() + } return sf } func (s *SearchEntry) Refresh() { - if s.Text == "" { - s.ActionItem.(*clearTextButton).Resource = theme.SearchIcon() - } else { - s.ActionItem.(*clearTextButton).Resource = theme.ContentClearIcon() - } + s.updateActionButton() s.Entry.Refresh() } @@ -45,6 +46,17 @@ func (s *SearchEntry) MinSize() fyne.Size { return fyne.NewSize(200, s.Entry.MinSize().Height) } +func (s *SearchEntry) updateActionButton() bool { + btn := s.ActionItem.(*clearTextButton) + oldResouce := btn.Resource + if s.Text == "" { + btn.Resource = theme.SearchIcon() + } else { + btn.Resource = theme.ContentClearIcon() + } + return oldResouce != btn.Resource +} + var _ fyne.Tappable = (*clearTextButton)(nil) type clearTextButton struct {