add scrollup scrolldown builtin cmd (#764)
* add scrollup scrolldown builtin cmd Scrollup/down move window pane without moving current cursor position. Default keybinding would be <c-y> for scrollup and <c-e> for scrolldown just like in vim. * limit scrolldown when reached bottom scrolodown will not allow empty space Fix typo
This commit is contained in:
parent
7005815671
commit
b4637f91aa
@ -17,9 +17,11 @@ var (
|
|||||||
"up",
|
"up",
|
||||||
"half-up",
|
"half-up",
|
||||||
"page-up",
|
"page-up",
|
||||||
|
"scrollup",
|
||||||
"down",
|
"down",
|
||||||
"half-down",
|
"half-down",
|
||||||
"page-down",
|
"page-down",
|
||||||
|
"scrolldown",
|
||||||
"updir",
|
"updir",
|
||||||
"open",
|
"open",
|
||||||
"quit",
|
"quit",
|
||||||
|
4
doc.go
4
doc.go
@ -19,9 +19,11 @@ The following commands are provided by lf:
|
|||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>' and '<pgup>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
|
scrollup (default '<c-y>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>' and '<pgdn>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
|
scrolldown (default '<c-e>')
|
||||||
updir (default 'h' and '<left>')
|
updir (default 'h' and '<left>')
|
||||||
open (default 'l' and '<right>')
|
open (default 'l' and '<right>')
|
||||||
top (default 'gg' and '<home>')
|
top (default 'gg' and '<home>')
|
||||||
@ -242,9 +244,11 @@ Quit lf and return to the shell.
|
|||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>' and '<pgup>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
|
scrollup (default '<c-y>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>' and '<pgdn>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
|
scrolldown (default '<c-e>')
|
||||||
|
|
||||||
Move the current file selection upwards/downwards by one/half a page/full page.
|
Move the current file selection upwards/downwards by one/half a page/full page.
|
||||||
|
|
||||||
|
@ -23,9 +23,11 @@ The following commands are provided by lf:
|
|||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>' and '<pgup>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
|
scrollup (default '<c-y>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>' and '<pgdn>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
|
scrolldown (default '<c-e>')
|
||||||
updir (default 'h' and '<left>')
|
updir (default 'h' and '<left>')
|
||||||
open (default 'l' and '<right>')
|
open (default 'l' and '<right>')
|
||||||
top (default 'gg' and '<home>')
|
top (default 'gg' and '<home>')
|
||||||
@ -249,9 +251,11 @@ Quit lf and return to the shell.
|
|||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>' and '<pgup>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
|
scrollup (default '<c-y>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>' and '<pgdn>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
|
scrolldown (default '<c-e>')
|
||||||
|
|
||||||
Move the current file selection upwards/downwards by one/half a page/full
|
Move the current file selection upwards/downwards by one/half a page/full
|
||||||
page.
|
page.
|
||||||
|
10
eval.go
10
eval.go
@ -807,6 +807,11 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav, true)
|
app.ui.loadFile(app.nav, true)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
case "scrollup":
|
||||||
|
if app.nav.scrollup(e.count) {
|
||||||
|
app.ui.loadFile(app.nav, true)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
case "down":
|
case "down":
|
||||||
if app.nav.down(e.count) {
|
if app.nav.down(e.count) {
|
||||||
app.ui.loadFile(app.nav, true)
|
app.ui.loadFile(app.nav, true)
|
||||||
@ -822,6 +827,11 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav, true)
|
app.ui.loadFile(app.nav, true)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
case "scrolldown":
|
||||||
|
if app.nav.scrolldown(e.count) {
|
||||||
|
app.ui.loadFile(app.nav, true)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
case "updir":
|
case "updir":
|
||||||
resetIncCmd(app)
|
resetIncCmd(app)
|
||||||
preChdir(app)
|
preChdir(app)
|
||||||
|
4
lf.1
4
lf.1
@ -35,9 +35,11 @@ The following commands are provided by lf:
|
|||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>' and '<pgup>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
|
scrollup (default '<c-y>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>' and '<pgdn>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
|
scrolldown (default '<c-e>')
|
||||||
updir (default 'h' and '<left>')
|
updir (default 'h' and '<left>')
|
||||||
open (default 'l' and '<right>')
|
open (default 'l' and '<right>')
|
||||||
top (default 'gg' and '<home>')
|
top (default 'gg' and '<home>')
|
||||||
@ -279,9 +281,11 @@ Quit lf and return to the shell.
|
|||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>' and '<pgup>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
|
scrollup (default '<c-y>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>' and '<pgdn>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
|
scrolldown (default '<c-e>')
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
Move the current file selection upwards/downwards by one/half a page/full page.
|
Move the current file selection upwards/downwards by one/half a page/full page.
|
||||||
|
58
nav.go
58
nav.go
@ -805,6 +805,64 @@ func (nav *nav) down(dist int) bool {
|
|||||||
return old != dir.ind
|
return old != dir.ind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) scrollup(dist int) bool {
|
||||||
|
dir := nav.currDir()
|
||||||
|
|
||||||
|
// when reached top do nothing
|
||||||
|
if istop := dir.ind == dir.pos; istop {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
old := dir.ind
|
||||||
|
|
||||||
|
minedge := min(nav.height/2, gOpts.scrolloff)
|
||||||
|
|
||||||
|
dir.pos += dist
|
||||||
|
|
||||||
|
// jump to ensure minedge when edge < minedge
|
||||||
|
edge := nav.height - dir.pos
|
||||||
|
delta := min(0, edge-minedge-1)
|
||||||
|
dir.pos = min(dir.pos, nav.height-minedge-1)
|
||||||
|
// update dir.ind accordingly
|
||||||
|
dir.ind = dir.ind + delta
|
||||||
|
|
||||||
|
dir.ind = min(dir.ind, dir.ind-(dir.pos-nav.height+1))
|
||||||
|
|
||||||
|
// prevent cursor disappearing downwards
|
||||||
|
dir.pos = min(dir.pos, nav.height-1)
|
||||||
|
|
||||||
|
return old != dir.ind
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) scrolldown(dist int) bool {
|
||||||
|
dir := nav.currDir()
|
||||||
|
maxind := len(dir.files) - 1
|
||||||
|
|
||||||
|
// reached bottom
|
||||||
|
if dir.ind-dir.pos > maxind-nav.height {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
old := dir.ind
|
||||||
|
|
||||||
|
minedge := min(nav.height/2, gOpts.scrolloff)
|
||||||
|
|
||||||
|
dir.pos -= dist
|
||||||
|
|
||||||
|
// jump to ensure minedge when edge < minedge
|
||||||
|
delta := min(0, dir.pos-minedge)
|
||||||
|
dir.pos = max(dir.pos, minedge)
|
||||||
|
// update dir.ind accordingly
|
||||||
|
dir.ind = dir.ind - delta
|
||||||
|
dir.ind = max(dir.ind, dir.ind-(dir.pos-minedge))
|
||||||
|
|
||||||
|
dir.ind = min(maxind, dir.ind)
|
||||||
|
// prevent disappearing
|
||||||
|
dir.pos = max(dir.pos, 0)
|
||||||
|
|
||||||
|
return old != dir.ind
|
||||||
|
}
|
||||||
|
|
||||||
func (nav *nav) updir() error {
|
func (nav *nav) updir() error {
|
||||||
if len(nav.dirs) <= 1 {
|
if len(nav.dirs) <= 1 {
|
||||||
return nil
|
return nil
|
||||||
|
2
opts.go
2
opts.go
@ -128,11 +128,13 @@ func init() {
|
|||||||
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
||||||
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
|
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
|
||||||
gOpts.keys["<pgup>"] = &callExpr{"page-up", nil, 1}
|
gOpts.keys["<pgup>"] = &callExpr{"page-up", nil, 1}
|
||||||
|
gOpts.keys["<c-y>"] = &callExpr{"scrollup", nil, 1}
|
||||||
gOpts.keys["j"] = &callExpr{"down", nil, 1}
|
gOpts.keys["j"] = &callExpr{"down", nil, 1}
|
||||||
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
||||||
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
||||||
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 1}
|
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 1}
|
||||||
gOpts.keys["<pgdn>"] = &callExpr{"page-down", nil, 1}
|
gOpts.keys["<pgdn>"] = &callExpr{"page-down", nil, 1}
|
||||||
|
gOpts.keys["<c-e>"] = &callExpr{"scrolldown", nil, 1}
|
||||||
gOpts.keys["h"] = &callExpr{"updir", nil, 1}
|
gOpts.keys["h"] = &callExpr{"updir", nil, 1}
|
||||||
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
||||||
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
||||||
|
Loading…
Reference in New Issue
Block a user