From 11b22887f4bec553c17ea71488f0f1eb9f44052d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Tue, 30 Jul 2024 13:12:00 -0700 Subject: [PATCH] remove preselection of items just hit 'a' if you want to select all --- internal/interactive/interactive.go | 24 ++++++++++-------------- main.go | 13 +++++-------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/internal/interactive/interactive.go b/internal/interactive/interactive.go index 5e860a5..49b4449 100644 --- a/internal/interactive/interactive.go +++ b/internal/interactive/interactive.go @@ -73,7 +73,7 @@ type model struct { files files.Files } -func newModel(fls []files.File, width, height int, readonly, preselected, once bool, workdir string, mode modes.Mode) model { +func newModel(fls []files.File, width, height int, readonly, once bool, workdir string, mode modes.Mode) model { var ( fwidth = int(math.Round(float64(width-woffset) * filenameColumn)) owidth = int(math.Round(float64(width-woffset) * pathColumn)) @@ -99,7 +99,7 @@ func newModel(fls []files.File, width, height int, readonly, preselected, once b mdl.workdir = filepath.Clean(workdir) } - rows := mdl.freshRows(preselected) + rows := mdl.freshRows() var datecolumn string switch mdl.mode { @@ -352,16 +352,12 @@ func (m model) selectedFiles() (outfile files.Files) { return false } */ -func (m *model) freshRows(preselected bool) (rows []table.Row) { +func (m *model) freshRows() (rows []table.Row) { for _, file := range m.files { row := newRow(file, m.workdir) if !m.readonly { - row = append(row, getCheck(preselected)) - } - if preselected { - m.selected[file.String()] = true - m.selectsize += file.Filesize() + row = append(row, getCheck(false)) } rows = append(rows, row) } @@ -511,8 +507,8 @@ func (m *model) sort() { m.table.SetRows(rows) } -func Select(fls files.Files, width, height int, readonly, preselected, once bool, workdir string, mode modes.Mode) (files.Files, modes.Mode, error) { - mdl := newModel(fls, width, height, readonly, preselected, once, workdir, mode) +func Select(fls files.Files, width, height int, readonly, once bool, workdir string, mode modes.Mode) (files.Files, modes.Mode, error) { + mdl := newModel(fls, width, height, readonly, once, workdir, mode) endmodel, err := tea.NewProgram(mdl).Run() if err != nil { return fls, 0, err @@ -562,16 +558,16 @@ func createTable(columns []table.Column, rows []table.Row, height int) table.Mod } func fixTableKeymap() table.KeyMap { - tbl := table.DefaultKeyMap() + keys := table.DefaultKeyMap() // remove spacebar from default page down keybind, but keep the rest - tbl.PageDown.SetKeys( - slices.DeleteFunc(tbl.PageDown.Keys(), func(s string) bool { + keys.PageDown.SetKeys( + slices.DeleteFunc(keys.PageDown.Keys(), func(s string) bool { return s == space })..., ) - return tbl + return keys } func makeStyle() table.Styles { diff --git a/main.go b/main.go index d19ae2f..71a739c 100644 --- a/main.go +++ b/main.go @@ -126,7 +126,7 @@ var ( fmt.Fprintln(os.Stdout, msg) return nil } - selected, mode, err = interactive.Select(infiles, termwidth, termheight, false, false, false, workdir, modes.Interactive) + selected, mode, err = interactive.Select(infiles, termwidth, termheight, false, false, workdir, modes.Interactive) if err != nil { return err } @@ -202,7 +202,6 @@ var ( Before: beforeTrash, Action: func(ctx *cli.Context) error { var filesToTrash files.Files - var selectall bool for _, arg := range ctx.Args().Slice() { file, e := files.NewDisk(arg) if e != nil || workdir != "" { @@ -211,7 +210,6 @@ var ( continue } filesToTrash = append(filesToTrash, file) - selectall = true } // if none of the args were files, then process find files based on filter @@ -225,10 +223,9 @@ var ( return nil } filesToTrash = append(filesToTrash, fls...) - selectall = !fltr.Blank() } - selected, _, err := interactive.Select(filesToTrash, termwidth, termheight, false, selectall, false, workdir, modes.Trashing) + selected, _, err := interactive.Select(filesToTrash, termwidth, termheight, false, false, workdir, modes.Trashing) if err != nil { return err } @@ -269,7 +266,7 @@ var ( } // display them - _, _, err = interactive.Select(fls, termwidth, termheight, true, false, noInterArg, workdir, modes.Listing) + _, _, err = interactive.Select(fls, termwidth, termheight, true, noInterArg, workdir, modes.Listing) return err }, @@ -293,7 +290,7 @@ var ( return err } - selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, all, workdir, modes.Restoring) + selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, workdir, modes.Restoring) if err != nil { return err } @@ -321,7 +318,7 @@ var ( return err } - selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, all, workdir, modes.Cleaning) + selected, _, err := interactive.Select(fls, termwidth, termheight, false, all, workdir, modes.Cleaning) if err != nil { return err }