From 1a03f7f23f863a396e4150978bdd31cc022eedcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Sun, 28 Jul 2024 23:31:38 -0700 Subject: [PATCH] cleanup model Update() a bit and repeat less --- internal/interactive/interactive.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/internal/interactive/interactive.go b/internal/interactive/interactive.go index f4cfc3c..a5832a2 100644 --- a/internal/interactive/interactive.go +++ b/internal/interactive/interactive.go @@ -203,15 +203,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, m.keys.invr): m.invertSelection() case key.Matches(msg, m.keys.clen): - if m.mode == modes.Interactive && len(m.selected) > 0 { - m.mode = modes.Cleaning - return m.quit(false) - } + return m.execute(modes.Cleaning) case key.Matches(msg, m.keys.rstr): - if m.mode == modes.Interactive && len(m.selected) > 0 { - m.mode = modes.Restoring - return m.quit(false) - } + return m.execute(modes.Restoring) case key.Matches(msg, m.keys.sort): m.sorting = m.sorting.Next() m.sort() @@ -319,6 +313,18 @@ func (m model) quit(unselect_all bool) (model, tea.Cmd) { return m, tea.Quit } +func (m model) execute(mode modes.Mode) (model, tea.Cmd) { + if m.mode != modes.Interactive || len(m.selected) <= 0 { + var cmd tea.Cmd + return m, cmd + } + + m.mode = mode + m.onlySelected() + m.table.SetStyles(makeUnselectedStyle()) + return m, tea.Quit +} + func (m model) selectedFiles() (outfile files.Files) { for _, file := range m.files { if m.selected[file.String()] {