add command to invert marks in current directory

This commit is contained in:
Olivier Perret 2016-10-09 18:07:57 +02:00
parent 4d8a37ebc9
commit 69ff83a4b0
6 changed files with 23 additions and 7 deletions

View File

@ -32,6 +32,7 @@ var (
"search",
"search-back",
"toggle",
"invert",
"yank",
"delete",
"paste",

1
doc.go
View File

@ -30,6 +30,7 @@ The following commands are provided by lf with default keybindings.
search (default "/")
search-back (default "?")
toggle (default "<space>")
invert (default "v")
yank (default "y")
delete (default "d")
paste (default "p")

View File

@ -34,6 +34,7 @@ The following commands are provided by lf with default keybindings.
search (default "/")
search-back (default "?")
toggle (default "<space>")
invert (default "v")
yank (default "y")
delete (default "d")
paste (default "p")

View File

@ -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)

24
nav.go
View File

@ -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() {

View File

@ -49,6 +49,7 @@ func init() {
gOpts.keys["/"] = &CallExpr{"search", nil}
gOpts.keys["?"] = &CallExpr{"search-back", nil}
gOpts.keys["<space>"] = &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}