add wrapscan option for cyclic search

Mentioned in #57.
This commit is contained in:
Gokcehan 2017-03-16 16:22:42 +03:00
parent 784d80ca30
commit 8bc975a858
6 changed files with 25 additions and 8 deletions

View File

@ -59,6 +59,9 @@ var (
"reverse",
"noreverse",
"reverse!",
"wrapscan",
"nowrapscan",
"wrapscan!",
"scrolloff",
"tabstop",
"filesep",

1
doc.go
View File

@ -70,6 +70,7 @@ The following options can be used to customize the behavior of lf:
hidden boolean (default off)
preview boolean (default on)
reverse boolean (default off)
wrapscan boolean (default on)
scrolloff integer (default 0)
tabstop integer (default 8)
filesep string (default ":")

View File

@ -74,6 +74,7 @@ The following options can be used to customize the behavior of lf:
hidden boolean (default off)
preview boolean (default on)
reverse boolean (default off)
wrapscan boolean (default on)
scrolloff integer (default 0)
tabstop integer (default 8)
filesep string (default ":")

View File

@ -44,6 +44,12 @@ func (e *setExpr) eval(app *app, args []string) {
case "reverse!":
gOpts.reverse = !gOpts.reverse
app.nav.renew(app.nav.height)
case "wrapscan":
gOpts.wrapscan = true
case "nowrapscan":
gOpts.wrapscan = false
case "wrapscan!":
gOpts.wrapscan = !gOpts.wrapscan
case "scrolloff":
n, err := strconv.Atoi(e.val)
if err != nil {

4
nav.go
View File

@ -372,6 +372,7 @@ func (nav *nav) searchNext() {
return
}
}
if gOpts.wrapscan {
for i := 0; i < last.ind; i++ {
if strings.Contains(last.fi[i].Name(), nav.search) {
nav.up(last.ind - i)
@ -379,6 +380,7 @@ func (nav *nav) searchNext() {
}
}
}
}
func (nav *nav) searchPrev() {
last := nav.currDir()
@ -388,6 +390,7 @@ func (nav *nav) searchPrev() {
return
}
}
if gOpts.wrapscan {
for i := len(last.fi) - 1; i > last.ind; i-- {
if strings.Contains(last.fi[i].Name(), nav.search) {
nav.down(i - last.ind)
@ -395,6 +398,7 @@ func (nav *nav) searchPrev() {
}
}
}
}
func (nav *nav) toggleMark(path string) {
if _, ok := nav.marks[path]; ok {

View File

@ -7,6 +7,7 @@ var gOpts struct {
hidden bool
preview bool
reverse bool
wrapscan bool
scrolloff int
tabstop int
filesep string
@ -27,6 +28,7 @@ func init() {
gOpts.hidden = false
gOpts.preview = true
gOpts.reverse = false
gOpts.wrapscan = true
gOpts.scrolloff = 0
gOpts.tabstop = 8
gOpts.filesep = ":"