From 8bc975a858d07e48f3e7cf3778aadce6688a3d69 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Thu, 16 Mar 2017 16:22:42 +0300 Subject: [PATCH] add wrapscan option for cyclic search Mentioned in #57. --- comp.go | 3 +++ doc.go | 1 + docstring.go | 1 + eval.go | 6 ++++++ nav.go | 20 ++++++++++++-------- opts.go | 2 ++ 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/comp.go b/comp.go index e070d6f..4340a67 100644 --- a/comp.go +++ b/comp.go @@ -59,6 +59,9 @@ var ( "reverse", "noreverse", "reverse!", + "wrapscan", + "nowrapscan", + "wrapscan!", "scrolloff", "tabstop", "filesep", diff --git a/doc.go b/doc.go index 38c4cc4..4efad37 100644 --- a/doc.go +++ b/doc.go @@ -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 ":") diff --git a/docstring.go b/docstring.go index e7b4821..4fb6725 100644 --- a/docstring.go +++ b/docstring.go @@ -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 ":") diff --git a/eval.go b/eval.go index cfead6b..94a1df8 100644 --- a/eval.go +++ b/eval.go @@ -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 { diff --git a/nav.go b/nav.go index 8451d59..95acee8 100644 --- a/nav.go +++ b/nav.go @@ -372,10 +372,12 @@ func (nav *nav) searchNext() { return } } - for i := 0; i < last.ind; i++ { - if strings.Contains(last.fi[i].Name(), nav.search) { - nav.up(last.ind - i) - 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) + return + } } } } @@ -388,10 +390,12 @@ func (nav *nav) searchPrev() { return } } - for i := len(last.fi) - 1; i > last.ind; i-- { - if strings.Contains(last.fi[i].Name(), nav.search) { - nav.down(i - last.ind) - 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) + return + } } } } diff --git a/opts.go b/opts.go index da6113d..afa7998 100644 --- a/opts.go +++ b/opts.go @@ -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 = ":"