parent
af113e71ef
commit
f7e778591a
2
comp.go
2
comp.go
@ -31,6 +31,8 @@ var (
|
||||
"read-shell-async",
|
||||
"search",
|
||||
"search-back",
|
||||
"search-next",
|
||||
"search-prev",
|
||||
"toggle",
|
||||
"invert",
|
||||
"yank",
|
||||
|
2
doc.go
2
doc.go
@ -29,6 +29,8 @@ The following commands are provided by lf with default keybindings:
|
||||
read-shell-async (default "&")
|
||||
search (default "/")
|
||||
search-back (default "?")
|
||||
search-next (default "n")
|
||||
search-prev (default "N")
|
||||
toggle (default "<space>")
|
||||
invert (default "v")
|
||||
yank (default "y")
|
||||
|
@ -33,6 +33,8 @@ The following commands are provided by lf with default keybindings:
|
||||
read-shell-async (default "&")
|
||||
search (default "/")
|
||||
search-back (default "?")
|
||||
search-next (default "n")
|
||||
search-prev (default "N")
|
||||
toggle (default "<space>")
|
||||
invert (default "v")
|
||||
yank (default "y")
|
||||
|
12
eval.go
12
eval.go
@ -262,6 +262,10 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdpref = "/"
|
||||
case "search-back":
|
||||
app.ui.cmdpref = "?"
|
||||
case "search-next":
|
||||
app.nav.searchNext()
|
||||
case "search-prev":
|
||||
app.nav.searchPrev()
|
||||
case "toggle":
|
||||
app.nav.toggle()
|
||||
case "invert":
|
||||
@ -405,12 +409,12 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.runShell(s, nil, false, true)
|
||||
case "/":
|
||||
log.Printf("search: %s", s)
|
||||
app.ui.message = "sorry, search is not implemented yet!"
|
||||
// TODO: implement
|
||||
app.nav.search = s
|
||||
app.nav.searchNext()
|
||||
case "?":
|
||||
log.Printf("search-back: %s", s)
|
||||
app.ui.message = "sorry, search-back is not implemented yet!"
|
||||
// TODO: implement
|
||||
app.nav.search = s
|
||||
app.nav.searchPrev()
|
||||
default:
|
||||
log.Printf("entering unknown execution prefix: %q", app.ui.cmdpref)
|
||||
}
|
||||
|
21
nav.go
21
nav.go
@ -180,6 +180,7 @@ type nav struct {
|
||||
marks map[string]bool
|
||||
saves map[string]bool
|
||||
height int
|
||||
search string
|
||||
}
|
||||
|
||||
func getDirs(wd string, height int) []*dir {
|
||||
@ -352,6 +353,26 @@ func (nav *nav) cd(wd string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) searchNext() {
|
||||
last := nav.currDir()
|
||||
for i := last.ind + 1; i < len(last.fi); i++ {
|
||||
if strings.Contains(last.fi[i].Name(), nav.search) {
|
||||
nav.down(i - last.ind)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) searchPrev() {
|
||||
last := nav.currDir()
|
||||
for i := last.ind - 1; i > 0; i-- {
|
||||
if strings.Contains(last.fi[i].Name(), nav.search) {
|
||||
nav.up(last.ind - i)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) toggleMark(path string) {
|
||||
if nav.marks[path] {
|
||||
delete(nav.marks, path)
|
||||
|
2
opts.go
2
opts.go
@ -54,6 +54,8 @@ func init() {
|
||||
gOpts.keys["&"] = &callExpr{"read-shell-async", nil}
|
||||
gOpts.keys["/"] = &callExpr{"search", nil}
|
||||
gOpts.keys["?"] = &callExpr{"search-back", nil}
|
||||
gOpts.keys["n"] = &callExpr{"search-next", nil}
|
||||
gOpts.keys["N"] = &callExpr{"search-prev", nil}
|
||||
gOpts.keys["<space>"] = &callExpr{"toggle", nil}
|
||||
gOpts.keys["v"] = &callExpr{"invert", nil}
|
||||
gOpts.keys["y"] = &callExpr{"yank", nil}
|
||||
|
Loading…
Reference in New Issue
Block a user