add "jump-next" and "jump-prev" (#755)
This commit is contained in:
parent
1718527e90
commit
375133e483
8
doc.go
8
doc.go
@ -250,6 +250,14 @@ A custom 'open' command can be defined to override this default.
|
||||
|
||||
(See also 'OPENER' variable and 'Opening Files' section)
|
||||
|
||||
jump-prev (default '[')
|
||||
|
||||
Change the current working directory to the previous jumplist item.
|
||||
|
||||
jump-next (default ']')
|
||||
|
||||
Change the current working directory to the next jumplist item.
|
||||
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
|
||||
|
@ -260,6 +260,14 @@ default.
|
||||
|
||||
(See also 'OPENER' variable and 'Opening Files' section)
|
||||
|
||||
jump-prev (default '[')
|
||||
|
||||
Change the current working directory to the previous jumplist item.
|
||||
|
||||
jump-next (default ']')
|
||||
|
||||
Change the current working directory to the next jumplist item.
|
||||
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
|
||||
|
21
eval.go
21
eval.go
@ -470,6 +470,7 @@ func preChdir(app *app) {
|
||||
}
|
||||
|
||||
func onChdir(app *app) {
|
||||
app.nav.addJumpList()
|
||||
if cmd, ok := gOpts.cmds["on-cd"]; ok {
|
||||
cmd.eval(app, nil)
|
||||
}
|
||||
@ -884,6 +885,26 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if cmd, ok := gOpts.cmds["open"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
}
|
||||
case "jump-prev":
|
||||
resetIncCmd(app)
|
||||
preChdir(app)
|
||||
for i := 0; i < e.count; i++ {
|
||||
app.nav.cdJumpListPrev()
|
||||
}
|
||||
app.ui.loadFile(app.nav, true)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
restartIncCmd(app)
|
||||
onChdir(app)
|
||||
case "jump-next":
|
||||
resetIncCmd(app)
|
||||
preChdir(app)
|
||||
for i := 0; i < e.count; i++ {
|
||||
app.nav.cdJumpListNext()
|
||||
}
|
||||
app.ui.loadFile(app.nav, true)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
restartIncCmd(app)
|
||||
onChdir(app)
|
||||
case "quit":
|
||||
app.quitChan <- struct{}{}
|
||||
case "top":
|
||||
|
12
lf.1
12
lf.1
@ -286,6 +286,18 @@ If the current file is a directory, then change the current directory to it, oth
|
||||
.PP
|
||||
(See also 'OPENER' variable and 'Opening Files' section)
|
||||
.PP
|
||||
.EX
|
||||
jump-prev (default '[')
|
||||
.EE
|
||||
.PP
|
||||
Change the current working directory to the previous jumplist item.
|
||||
.PP
|
||||
.EX
|
||||
jump-next (default ']')
|
||||
.EE
|
||||
.PP
|
||||
Change the current working directory to the next jumplist item.
|
||||
.PP
|
||||
.EX
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
|
37
nav.go
37
nav.go
@ -364,6 +364,8 @@ type nav struct {
|
||||
searchPos int
|
||||
prevFilter []string
|
||||
volatilePreview bool
|
||||
jumpList []string
|
||||
jumpListInd int
|
||||
}
|
||||
|
||||
func (nav *nav) loadDirInternal(path string) *dir {
|
||||
@ -480,13 +482,46 @@ func newNav(height int) *nav {
|
||||
selections: make(map[string]int),
|
||||
selectionInd: 0,
|
||||
height: height,
|
||||
jumpList: make([]string, 0),
|
||||
jumpListInd: -1,
|
||||
}
|
||||
|
||||
nav.getDirs(wd)
|
||||
nav.addJumpList()
|
||||
|
||||
return nav
|
||||
}
|
||||
|
||||
func (nav *nav) addJumpList() {
|
||||
currPath := nav.currDir().path
|
||||
if nav.jumpListInd >= 0 && nav.jumpListInd < len(nav.jumpList)-1 {
|
||||
if nav.jumpList[nav.jumpListInd] == currPath {
|
||||
// walking the jumpList
|
||||
return
|
||||
}
|
||||
nav.jumpList = nav.jumpList[:nav.jumpListInd+1]
|
||||
}
|
||||
if len(nav.jumpList) == 0 || nav.jumpList[len(nav.jumpList)-1] != currPath {
|
||||
nav.jumpList = append(nav.jumpList, currPath)
|
||||
}
|
||||
nav.jumpListInd = len(nav.jumpList) - 1
|
||||
}
|
||||
|
||||
func (nav *nav) cdJumpListPrev() {
|
||||
// currPath := nav.currDir().path
|
||||
if nav.jumpListInd > 0 {
|
||||
nav.jumpListInd -= 1
|
||||
nav.cd(nav.jumpList[nav.jumpListInd])
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) cdJumpListNext() {
|
||||
if nav.jumpListInd < len(nav.jumpList)-1 {
|
||||
nav.jumpListInd += 1
|
||||
nav.cd(nav.jumpList[nav.jumpListInd])
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) renew() {
|
||||
for _, d := range nav.dirs {
|
||||
nav.checkDir(d)
|
||||
@ -1171,7 +1206,7 @@ func (nav *nav) cd(wd string) error {
|
||||
}
|
||||
|
||||
nav.getDirs(wd)
|
||||
|
||||
nav.addJumpList()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
2
opts.go
2
opts.go
@ -142,6 +142,8 @@ 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["["] = &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}
|
||||
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
||||
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
|
||||
|
Loading…
Reference in New Issue
Block a user