From 69ff83a4b01f6d5052feb7908be4290160ee7d3a Mon Sep 17 00:00:00 2001 From: Olivier Perret Date: Sun, 9 Oct 2016 18:07:57 +0200 Subject: [PATCH] add command to invert marks in current directory --- comp.go | 1 + doc.go | 1 + docstring.go | 1 + eval.go | 2 ++ nav.go | 24 +++++++++++++++++------- opts.go | 1 + 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/comp.go b/comp.go index 40fceac..6195a6f 100644 --- a/comp.go +++ b/comp.go @@ -32,6 +32,7 @@ var ( "search", "search-back", "toggle", + "invert", "yank", "delete", "paste", diff --git a/doc.go b/doc.go index 00265ff..c3dde83 100644 --- a/doc.go +++ b/doc.go @@ -30,6 +30,7 @@ The following commands are provided by lf with default keybindings. search (default "/") search-back (default "?") toggle (default "") + invert (default "v") yank (default "y") delete (default "d") paste (default "p") diff --git a/docstring.go b/docstring.go index 6e24e8b..e53f16a 100644 --- a/docstring.go +++ b/docstring.go @@ -34,6 +34,7 @@ The following commands are provided by lf with default keybindings. search (default "/") search-back (default "?") toggle (default "") + invert (default "v") yank (default "y") delete (default "d") paste (default "p") diff --git a/eval.go b/eval.go index 99f30e5..9d735fa 100644 --- a/eval.go +++ b/eval.go @@ -280,6 +280,8 @@ func (e *CallExpr) eval(app *App, args []string) { // TODO: implement case "toggle": app.nav.toggle() + case "invert": + app.nav.invert() case "yank": if err := app.nav.save(true); err != nil { msg := fmt.Sprintf("yank: %s", err) diff --git a/nav.go b/nav.go index 48310d1..d0c928b 100644 --- a/nav.go +++ b/nav.go @@ -343,22 +343,32 @@ func (nav *Nav) cd(wd string) error { return nil } -func (nav *Nav) toggle() { - if nav.currEmpty() { - return - } - - path := nav.currPath() - +func (nav *Nav) toggleMark(path string) { if nav.marks[path] { delete(nav.marks, path) } else { nav.marks[path] = true } +} + +func (nav *Nav) toggle() { + if nav.currEmpty() { + return + } + + nav.toggleMark(nav.currPath()) nav.down(1) } +func (nav *Nav) invert() { + last := nav.currDir() + for _, f := range last.fi { + path := filepath.Join(last.path, f.Name()) + nav.toggleMark(path) + } +} + func (nav *Nav) save(keep bool) error { if len(nav.marks) == 0 { if nav.currEmpty() { diff --git a/opts.go b/opts.go index c16521e..7532d09 100644 --- a/opts.go +++ b/opts.go @@ -49,6 +49,7 @@ func init() { gOpts.keys["/"] = &CallExpr{"search", nil} gOpts.keys["?"] = &CallExpr{"search-back", nil} gOpts.keys[""] = &CallExpr{"toggle", nil} + gOpts.keys["v"] = &CallExpr{"invert", nil} gOpts.keys["y"] = &CallExpr{"yank", nil} gOpts.keys["d"] = &CallExpr{"delete", nil} gOpts.keys["p"] = &CallExpr{"paste", nil}