add half-up/half-down/page-up/page-down commands

This commit is contained in:
Gokcehan 2016-09-09 00:04:44 +03:00
parent 34c58b634a
commit a31ce17b90
4 changed files with 31 additions and 9 deletions

View File

@ -3,7 +3,11 @@
## Keys
up (default "k" and "<up>")
half-up (default "<c-u>")
page-up (default "<c-b>")
down (default "j" and "<down>")
half-down (default "<c-d>")
page-down (default "<c-f>")
updir (default "h" and "<left>")
open (default "l" and "<right>")
quit (default "q")

16
eval.go
View File

@ -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 {

16
nav.go
View File

@ -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 {

View File

@ -31,8 +31,12 @@ func init() {
gOpts.keys["k"] = &CallExpr{"up", nil}
gOpts.keys["<up>"] = &CallExpr{"up", nil}
gOpts.keys["<c-u>"] = &CallExpr{"half-up", nil}
gOpts.keys["<c-b>"] = &CallExpr{"page-up", nil}
gOpts.keys["j"] = &CallExpr{"down", nil}
gOpts.keys["<down>"] = &CallExpr{"down", nil}
gOpts.keys["<c-d>"] = &CallExpr{"half-down", nil}
gOpts.keys["<c-f>"] = &CallExpr{"page-down", nil}
gOpts.keys["h"] = &CallExpr{"updir", nil}
gOpts.keys["<left>"] = &CallExpr{"updir", nil}
gOpts.keys["l"] = &CallExpr{"open", nil}