From 674bc37177828ba83238019405be42619d84c85e Mon Sep 17 00:00:00 2001 From: Azy <1213581294@qq.com> Date: Tue, 18 Apr 2023 18:35:44 +0800 Subject: [PATCH] feat(selection): unselected before quit (#41) Co-authored-by: zhiyang.wang --- components/selection.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/selection.go b/components/selection.go index c28f10d..04c810e 100644 --- a/components/selection.go +++ b/components/selection.go @@ -265,6 +265,7 @@ func (s *Selection) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } if key.Matches(msg, s.Keymap.Quit) { + s.unselectAll() return s, tea.Quit } @@ -473,6 +474,13 @@ func (s *Selection) selectAll() { } } +// unselectAll change all item to unSelected +func (s *Selection) unselectAll() { + for idx := range s.Choices { + delete(s.Selected, idx) + } +} + // flip all Selected func (s *Selection) flip() { for _, choice := range s.Choices {