From 11666caf6e016a884899248551fe137bff989d97 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Fri, 29 Nov 2024 17:13:33 +0100 Subject: [PATCH] fix: reset marked rows when sorting or filtering is changed fixes #388 --- tui/filter.go | 2 ++ tui/filter_test.go | 6 ++++++ tui/keys_test.go | 8 ++++++++ tui/sort.go | 2 ++ 4 files changed, 18 insertions(+) diff --git a/tui/filter.go b/tui/filter.go index 12846daa6..d273e97e8 100644 --- a/tui/filter.go +++ b/tui/filter.go @@ -20,6 +20,8 @@ func (ui *UI) showFilterInput() { } if ui.filteringInput == nil { + ui.markedRows = make(map[int]struct{}) + ui.filteringInput = tview.NewInputField() if !ui.UseColors { diff --git a/tui/filter_test.go b/tui/filter_test.go index 562a5806c..a69c41650 100644 --- a/tui/filter_test.go +++ b/tui/filter_test.go @@ -29,11 +29,17 @@ func TestFiltering(t *testing.T) { f() } + // mark the item for deletion + ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, ' ', 0)) + assert.Equal(t, 1, len(ui.markedRows)) + ui.showFilterInput() ui.filterValue = "" ui.showDir() assert.Contains(t, ui.table.GetCell(0, 0).Text, "ccc") // nothing is filtered + // marking should be dropped after sorting + assert.Equal(t, 0, len(ui.markedRows)) ui.filterValue = "aa" ui.showDir() diff --git a/tui/keys_test.go b/tui/keys_test.go index 7b352c4ad..6616dfa33 100644 --- a/tui/keys_test.go +++ b/tui/keys_test.go @@ -973,6 +973,11 @@ func TestSorting(t *testing.T) { assert.Equal(t, "test_dir", ui.currentDir.GetName()) + ui.table.Select(1, 0) + // mark the item for deletion + ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, ' ', 0)) + assert.Equal(t, 1, len(ui.markedRows)) + ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 's', 0)) assert.Equal(t, "size", ui.sortBy) ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'C', 0)) @@ -981,6 +986,9 @@ func TestSorting(t *testing.T) { assert.Equal(t, "name", ui.sortBy) ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'M', 0)) assert.Equal(t, "mtime", ui.sortBy) + + // marking should be dropped after sorting + assert.Equal(t, 0, len(ui.markedRows)) } func TestShowFile(t *testing.T) { diff --git a/tui/sort.go b/tui/sort.go index 049b79a35..ab10caf4a 100644 --- a/tui/sort.go +++ b/tui/sort.go @@ -28,6 +28,8 @@ func (ui *UI) SetDefaultSorting(by, order string) { } func (ui *UI) setSorting(newOrder string) { + ui.markedRows = make(map[int]struct{}) + if newOrder == ui.sortBy { if ui.sortOrder == ascOrder { ui.sortOrder = descOrder