From ba20b23767c8c6ddc99f0163782106d6188893fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Sat, 29 Jun 2024 19:56:51 -0700 Subject: [PATCH] show only selected rows when confirming --- internal/tables/tables.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/tables/tables.go b/internal/tables/tables.go index 6d81c40..cd27d70 100644 --- a/internal/tables/tables.go +++ b/internal/tables/tables.go @@ -246,7 +246,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.toggleItem(m.table.Cursor()) case key.Matches(msg, m.keys.doit): if !m.readonly && m.mode != modes.Interactive { - return m, tea.Quit + return m.quit(false) } case key.Matches(msg, m.keys.nada): m.unselectAll() @@ -352,11 +352,25 @@ func (m model) footer() string { func (m model) quit(unselect_all bool) (model, tea.Cmd) { if unselect_all { m.unselectAll() + } else { + m.onlySelected() } m.table.SetStyles(makeUnselectedStyle()) return m, tea.Quit } +func (m *model) onlySelected() { + var rows = make([]table.Row, 0) + for _, row := range m.table.Rows() { + if row[4] == check { + rows = append(rows, row) + } else { + rows = append(rows, table.Row{}) + } + } + m.table.SetRows(rows) +} + // updateRow updates row of `index` with `row` func (m *model) updateRow(index int, selected bool) { rows := m.table.Rows()