From ffdcb71897e6a4da0877cada796312d42dac0363 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Fri, 17 Jul 2020 02:12:10 +0300 Subject: [PATCH] make select work properly with loading directories Related #370 --- nav.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/nav.go b/nav.go index 3a1d3c8..f795600 100644 --- a/nav.go +++ b/nav.go @@ -311,15 +311,16 @@ func (nav *nav) checkDir(dir *dir) { switch { case s.ModTime().After(dir.loadTime): + dir.loading = true + dir.loadTime = time.Now() go func() { - dir.loadTime = time.Now() nd := newDir(dir.path) nd.sort() nav.dirChan <- nd }() case dir.sortType != gOpts.sortType: + dir.loading = true go func() { - dir.loading = true dir.sort() dir.loading = false nav.dirChan <- dir @@ -868,7 +869,11 @@ func (nav *nav) rename() error { } dir := nav.loadDir(filepath.Dir(newPath)) - dir.files = append(dir.files, &file{FileInfo: lstat}) + + if dir.loading { + dir.files = append(dir.files, &file{FileInfo: lstat}) + } + dir.sel(lstat.Name(), nav.height) return nil @@ -923,12 +928,13 @@ func (nav *nav) sel(path string) error { base := filepath.Base(path) last := nav.dirs[len(nav.dirs)-1] + if last.loading { last.files = append(last.files, &file{FileInfo: lstat}) - } else { - last.sel(base, nav.height) } + last.sel(base, nav.height) + return nil }