From a31ce17b9045d3a114446afaa3f841715c123986 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Fri, 9 Sep 2016 00:04:44 +0300 Subject: [PATCH] add half-up/half-down/page-up/page-down commands --- doc/reference.md | 4 ++++ eval.go | 16 ++++++++++++++-- nav.go | 16 +++++++++------- opts.go | 4 ++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/doc/reference.md b/doc/reference.md index 4f4fca5..47cedbf 100644 --- a/doc/reference.md +++ b/doc/reference.md @@ -3,7 +3,11 @@ ## Keys up (default "k" and "") + half-up (default "") + page-up (default "") down (default "j" and "") + half-down (default "") + page-down (default "") updir (default "h" and "") open (default "l" and "") quit (default "q") diff --git a/eval.go b/eval.go index ccf3152..b77852e 100644 --- a/eval.go +++ b/eval.go @@ -124,10 +124,22 @@ func (e *CallExpr) eval(app *App, args []string) { // TODO: check for extra toks in each case switch e.name { case "up": - app.nav.up() + app.nav.up(1) + app.ui.echoFileInfo(app.nav) + case "half-up": + app.nav.up(app.nav.height / 2) + app.ui.echoFileInfo(app.nav) + case "page-up": + app.nav.up(app.nav.height) app.ui.echoFileInfo(app.nav) case "down": - app.nav.down() + app.nav.down(1) + app.ui.echoFileInfo(app.nav) + case "half-down": + app.nav.down(app.nav.height / 2) + app.ui.echoFileInfo(app.nav) + case "page-down": + app.nav.down(app.nav.height) app.ui.echoFileInfo(app.nav) case "updir": if err := app.nav.updir(); err != nil { diff --git a/nav.go b/nav.go index 0bd8b2f..17c0e70 100644 --- a/nav.go +++ b/nav.go @@ -233,21 +233,22 @@ func (nav *Nav) renew(height int) { } } -func (nav *Nav) up() { +func (nav *Nav) up(dist int) { dir := nav.currDir() if dir.ind == 0 { return } - dir.ind-- + dir.ind -= dist + dir.ind = max(0, dir.ind) - dir.pos-- + dir.pos -= dist edge := min(gOpts.scrolloff, dir.ind) dir.pos = max(dir.pos, edge) } -func (nav *Nav) down() { +func (nav *Nav) down(dist int) { dir := nav.currDir() maxind := len(dir.fi) - 1 @@ -256,9 +257,10 @@ func (nav *Nav) down() { return } - dir.ind++ + dir.ind += dist + dir.ind = min(maxind, dir.ind) - dir.pos++ + dir.pos += dist edge := min(gOpts.scrolloff, maxind-dir.ind) // use a smaller value when the height is even and scrolloff is maxed @@ -349,7 +351,7 @@ func (nav *Nav) toggle() { nav.marks[path] = true } - nav.down() + nav.down(1) } func (nav *Nav) save(keep bool) error { diff --git a/opts.go b/opts.go index a0abc56..0e07fc6 100644 --- a/opts.go +++ b/opts.go @@ -31,8 +31,12 @@ func init() { gOpts.keys["k"] = &CallExpr{"up", nil} gOpts.keys[""] = &CallExpr{"up", nil} + gOpts.keys[""] = &CallExpr{"half-up", nil} + gOpts.keys[""] = &CallExpr{"page-up", nil} gOpts.keys["j"] = &CallExpr{"down", nil} gOpts.keys[""] = &CallExpr{"down", nil} + gOpts.keys[""] = &CallExpr{"half-down", nil} + gOpts.keys[""] = &CallExpr{"page-down", nil} gOpts.keys["h"] = &CallExpr{"updir", nil} gOpts.keys[""] = &CallExpr{"updir", nil} gOpts.keys["l"] = &CallExpr{"open", nil}