Add support for moving to a specific line (#1196)

* Add support for moving to a specific line

* Update documentation
This commit is contained in:
Joe Lim authored and GitHub committed 2023-04-08 23:40:16 +03:00
1 parent 27d316c006
commit b5c83dbf7a
6 files changed
+36 -8

No files matched your search

+1
View File
@@ -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')
+3 -1
View File
@@ -332,7 +332,9 @@ Change the current working directory to the next/previous jumplist item.
top (default 'gg' and '<home>')
bottom (default 'G' and '<end>')
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.
high (default 'H')
middle (default 'M')
+14 -2
View File
@@ -1425,7 +1425,13 @@ 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)
}
@@ -1433,7 +1439,13 @@ func (e *callExpr) eval(app *app, args []string) {
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)
}
+1 -1
View File
@@ -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')
+13
View File
@@ -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)
+4 -4
View File
@@ -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}