avoid loading redundant previews for up/down

cc #531
This commit is contained in:
Gokcehan 2021-01-18 21:30:52 +03:00
parent 2af2c6de31
commit f54acae958
2 changed files with 36 additions and 22 deletions

18
eval.go
View File

@ -606,44 +606,50 @@ func (e *callExpr) eval(app *app, args []string) {
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.up(e.count)
if app.nav.up(e.count) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "half-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.up(e.count * app.nav.height / 2)
if app.nav.up(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "page-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.up(e.count * app.nav.height)
if app.nav.up(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.down(e.count)
if app.nav.down(e.count) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "half-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.down(e.count * app.nav.height / 2)
if app.nav.down(e.count * app.nav.height / 2) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "page-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.down(e.count * app.nav.height)
if app.nav.down(e.count * app.nav.height) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "updir":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)

16
nav.go
View File

@ -590,14 +590,16 @@ func (nav *nav) sort() {
}
}
func (nav *nav) up(dist int) {
func (nav *nav) up(dist int) bool {
dir := nav.currDir()
old := dir.ind
if dir.ind == 0 {
if gOpts.wrapscroll {
nav.bottom()
}
return
return old != dir.ind
}
dir.ind -= dist
@ -606,18 +608,22 @@ func (nav *nav) up(dist int) {
dir.pos -= dist
edge := min(min(nav.height/2, gOpts.scrolloff), dir.ind)
dir.pos = max(dir.pos, edge)
return old != dir.ind
}
func (nav *nav) down(dist int) {
func (nav *nav) down(dist int) bool {
dir := nav.currDir()
old := dir.ind
maxind := len(dir.files) - 1
if dir.ind >= maxind {
if gOpts.wrapscroll {
nav.top()
}
return
return old != dir.ind
}
dir.ind += dist
@ -632,6 +638,8 @@ func (nav *nav) down(dist int) {
dir.pos = min(dir.pos, nav.height-edge-1)
dir.pos = min(dir.pos, maxind)
return old != dir.ind
}
func (nav *nav) updir() error {