Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down