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", "reverse",
"noreverse", "noreverse",
"reverse!", "reverse!",
"wrapscan",
"nowrapscan",
"wrapscan!",
"scrolloff", "scrolloff",
"tabstop", "tabstop",
"filesep", "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) hidden boolean (default off)
preview boolean (default on) preview boolean (default on)
reverse boolean (default off) reverse boolean (default off)
wrapscan boolean (default on)
scrolloff integer (default 0) scrolloff integer (default 0)
tabstop integer (default 8) tabstop integer (default 8)
filesep string (default ":") 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) hidden boolean (default off)
preview boolean (default on) preview boolean (default on)
reverse boolean (default off) reverse boolean (default off)
wrapscan boolean (default on)
scrolloff integer (default 0) scrolloff integer (default 0)
tabstop integer (default 8) tabstop integer (default 8)
filesep string (default ":") filesep string (default ":")

View File

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

4
nav.go
View File

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

View File

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