Skip to content

Commit

Permalink
fix: reset marked rows when sorting or filtering is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
dundee committed Nov 29, 2024
1 parent 31f7f83 commit 10a5fb3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tui/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions tui/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions tui/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions tui/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 10a5fb3

Please sign in to comment.