Add VIMs hi/mid/lo-screen commands (#824)

* add hi/mid/lo-screen commands and default keybindings

* doc
This commit is contained in:
Christian Zangl 2022-05-08 12:58:56 +02:00 committed by GitHub
parent 50f11ad3de
commit 01fe12b2ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 0 deletions

9
doc.go
View File

@ -31,6 +31,9 @@ The following commands are provided by lf:
jump-prev (default '[')
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
hi-screen (default 'H')
mid-screen (default 'M')
lo-screen (default 'L')
toggle
invert (default 'v')
unselect (default 'u')
@ -295,6 +298,12 @@ Change the current working directory to the next/previous jumplist item.
Move the current file selection to the top/bottom of the directory.
hi-screen (default 'H')
mid-screen (default 'M')
lo-screen (default 'L')
Move the current file selection to the top/middle/bottom of the screen.
toggle
Toggle the selection of the current file or files given as arguments.

View File

@ -35,6 +35,9 @@ The following commands are provided by lf:
jump-prev (default '[')
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
hi-screen (default 'H')
mid-screen (default 'M')
lo-screen (default 'L')
toggle
invert (default 'v')
unselect (default 'u')
@ -307,6 +310,12 @@ Change the current working directory to the next/previous jumplist item.
Move the current file selection to the top/bottom of the directory.
hi-screen (default 'H')
mid-screen (default 'M')
lo-screen (default 'L')
Move the current file selection to the top/middle/bottom of the screen.
toggle
Toggle the selection of the current file or files given as arguments.

24
eval.go
View File

@ -963,6 +963,30 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "hi-screen":
if !app.nav.init {
return
}
if app.nav.hiScreen() {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "mid-screen":
if !app.nav.init {
return
}
if app.nav.midScreen() {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "lo-screen":
if !app.nav.init {
return
}
if app.nav.loScreen() {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "toggle":
if !app.nav.init {
return

11
lf.1
View File

@ -46,6 +46,9 @@ The following commands are provided by lf:
jump-prev (default '[')
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
hi-screen (default 'H')
mid-screen (default 'M')
lo-screen (default 'L')
toggle
invert (default 'v')
unselect (default 'u')
@ -343,6 +346,14 @@ Change the current working directory to the next/previous jumplist item.
.PP
Move the current file selection to the top/bottom of the directory.
.PP
.EX
hi-screen (default 'H')
mid-screen (default 'M')
lo-screen (default 'L')
.EE
.PP
Move the current file selection to the top/middle/bottom of the screen.
.PP
.EX
toggle
.EE

47
nav.go
View File

@ -943,6 +943,53 @@ func (nav *nav) bottom() bool {
return old != dir.ind
}
func (nav *nav) hiScreen() bool {
dir := nav.currDir()
old := dir.ind
beg := max(dir.ind-dir.pos, 0)
offs := gOpts.scrolloff
if beg == 0 {
offs = 0
}
dir.ind = beg + offs
dir.pos = offs
return old != dir.ind
}
func (nav *nav) midScreen() bool {
dir := nav.currDir()
old := dir.ind
beg := max(dir.ind-dir.pos, 0)
end := min(beg+nav.height, len(dir.files))
half := (end - beg) / 2
dir.ind = beg + half
dir.pos = half
return old != dir.ind
}
func (nav *nav) loScreen() bool {
dir := nav.currDir()
old := dir.ind
beg := max(dir.ind-dir.pos, 0)
end := min(beg+nav.height, len(dir.files))
offs := gOpts.scrolloff
if end == len(dir.files) {
offs = 0
}
dir.ind = end - 1 - offs
dir.pos = end - beg - 1 - offs
return old != dir.ind
}
func (nav *nav) toggleSelection(path string) {
if _, ok := nav.selections[path]; ok {
delete(nav.selections, path)

View File

@ -146,6 +146,9 @@ func init() {
gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
gOpts.keys["H"] = &callExpr{"hi-screen", nil, 1}
gOpts.keys["M"] = &callExpr{"mid-screen", nil, 1}
gOpts.keys["L"] = &callExpr{"lo-screen", nil, 1}
gOpts.keys["["] = &callExpr{"jump-prev", nil, 1}
gOpts.keys["]"] = &callExpr{"jump-next", nil, 1}
gOpts.keys["<space>"] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1}