From e0317611ef892cf58c34d26c66a4429c75eff448 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Tue, 19 Jan 2021 01:47:09 +0300 Subject: [PATCH] avoid loading redundant previews for top/bottom cc #531 --- eval.go | 14 ++++++++------ nav.go | 12 ++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/eval.go b/eval.go index 020be46..789f41e 100644 --- a/eval.go +++ b/eval.go @@ -719,16 +719,18 @@ func (e *callExpr) eval(app *app, args []string) { if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { normal(app) } - app.nav.top() - app.ui.loadFile(app.nav, true) - app.ui.loadFileInfo(app.nav) + if app.nav.top() { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) + } case "bottom": if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { normal(app) } - app.nav.bottom() - app.ui.loadFile(app.nav, true) - app.ui.loadFileInfo(app.nav) + if app.nav.bottom() { + app.ui.loadFile(app.nav, true) + app.ui.loadFileInfo(app.nav) + } case "toggle": if len(e.args) == 0 { app.nav.toggle() diff --git a/nav.go b/nav.go index 6c4b26f..2b25fbf 100644 --- a/nav.go +++ b/nav.go @@ -677,18 +677,26 @@ func (nav *nav) open() error { return nil } -func (nav *nav) top() { +func (nav *nav) top() bool { dir := nav.currDir() + old := dir.ind + dir.ind = 0 dir.pos = 0 + + return old != dir.ind } -func (nav *nav) bottom() { +func (nav *nav) bottom() bool { dir := nav.currDir() + old := dir.ind + dir.ind = len(dir.files) - 1 dir.pos = min(dir.ind, nav.height-1) + + return old != dir.ind } func (nav *nav) toggleSelection(path string) {