Skip to content

Commit

Permalink
Add support for moving to a specific line (#1196)
Browse files Browse the repository at this point in the history
* Add support for moving to a specific line

* Update documentation
  • Loading branch information
joelim-work committed Apr 8, 2023
1 parent 27d316c commit b5c83db
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ Change the current working directory to the next/previous jumplist item.
bottom (default 'G' and '<end>')
Move the current file selection to the top/bottom of the directory.
A count can be specified to move to a specific line, for example use `3G` to move to the third line.
high (default 'H')
middle (default 'M')
Expand Down
4 changes: 3 additions & 1 deletion docstring.go

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

16 changes: 14 additions & 2 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1425,15 +1425,27 @@ func (e *callExpr) eval(app *app, args []string) {
if !app.nav.init {
return
}
if app.nav.top() {
var moved bool
if e.count == 0 {
moved = app.nav.top()
} else {
moved = app.nav.move(e.count - 1)
}
if moved {
app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
}
case "bottom":
if !app.nav.init {
return
}
if app.nav.bottom() {
var moved bool
if e.count == 0 {
moved = app.nav.bottom()
} else {
moved = app.nav.move(e.count - 1)
}
if moved {
app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
}
Expand Down
2 changes: 1 addition & 1 deletion lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ Change the current working directory to the next/previous jumplist item.
bottom (default 'G' and '<end>')
.EE
.PP
Move the current file selection to the top/bottom of the directory.
Move the current file selection to the top/bottom of the directory. A count can be specified to move to a specific line, for example use `3G` to move to the third line.
.PP
.EX
high (default 'H')
Expand Down
13 changes: 13 additions & 0 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,19 @@ func (nav *nav) low() bool {
return old != dir.ind
}

func (nav *nav) move(index int) bool {
old := nav.currDir().ind

switch {
case index < old:
return nav.up(old - index)
case index > old:
return nav.down(index - old)
default:
return false
}
}

func (nav *nav) toggleSelection(path string) {
if _, ok := nav.selections[path]; ok {
delete(nav.selections, path)
Expand Down
8 changes: 4 additions & 4 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ func init() {
gOpts.keys["l"] = &callExpr{"open", nil, 1}
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
gOpts.keys["gg"] = &callExpr{"top", nil, 0}
gOpts.keys["<home>"] = &callExpr{"top", nil, 0}
gOpts.keys["G"] = &callExpr{"bottom", nil, 0}
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 0}
gOpts.keys["H"] = &callExpr{"high", nil, 1}
gOpts.keys["M"] = &callExpr{"middle", nil, 1}
gOpts.keys["L"] = &callExpr{"low", nil, 1}
Expand Down

0 comments on commit b5c83db

Please sign in to comment.