add an option to disable directory cache (#673)
* add an option to disable directory cache * change option name to `dircache` * change 4 whitespaces to tab
This commit is contained in:
1 parent
75eba115d2
commit
ee5b3f4813
4 files changed
+48
-29
No files matched your search
@@ -372,13 +372,15 @@ func (app *app) loop() {
|
||||
case d := <-app.nav.dirChan:
|
||||
app.nav.checkDir(d)
|
||||
|
||||
prev, ok := app.nav.dirCache[d.path]
|
||||
if ok {
|
||||
d.ind = prev.ind
|
||||
d.sel(prev.name(), app.nav.height)
|
||||
}
|
||||
if gOpts.dircache {
|
||||
prev, ok := app.nav.dirCache[d.path]
|
||||
if ok {
|
||||
d.ind = prev.ind
|
||||
d.sel(prev.name(), app.nav.height)
|
||||
}
|
||||
|
||||
app.nav.dirCache[d.path] = d
|
||||
app.nav.dirCache[d.path] = d
|
||||
}
|
||||
|
||||
for i := range app.nav.dirs {
|
||||
if app.nav.dirs[i].path == d.path {
|
||||
|
||||
@@ -26,6 +26,12 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.autoquit = false
|
||||
case "autoquit!":
|
||||
gOpts.autoquit = !gOpts.autoquit
|
||||
case "dircache":
|
||||
gOpts.dircache = true
|
||||
case "nodircache":
|
||||
gOpts.dircache = false
|
||||
case "dircache!":
|
||||
gOpts.dircache = !gOpts.dircache
|
||||
case "dircounts":
|
||||
gOpts.dircounts = true
|
||||
case "nodircounts":
|
||||
|
||||
@@ -332,33 +332,42 @@ type nav struct {
|
||||
volatilePreview bool
|
||||
}
|
||||
|
||||
func (nav *nav) loadDir(path string) *dir {
|
||||
d, ok := nav.dirCache[path]
|
||||
if !ok {
|
||||
d := &dir{
|
||||
loading: true,
|
||||
loadTime: time.Now(),
|
||||
path: path,
|
||||
sortType: gOpts.sortType,
|
||||
hiddenfiles: gOpts.hiddenfiles,
|
||||
ignorecase: gOpts.ignorecase,
|
||||
ignoredia: gOpts.ignoredia,
|
||||
}
|
||||
nav.dirCache[path] = d
|
||||
go func() {
|
||||
d := newDir(path)
|
||||
d.sort()
|
||||
d.ind, d.pos = 0, 0
|
||||
nav.dirChan <- d
|
||||
}()
|
||||
return d
|
||||
func (nav *nav) loadDirInternal(path string) *dir {
|
||||
d := &dir{
|
||||
loading: true,
|
||||
loadTime: time.Now(),
|
||||
path: path,
|
||||
sortType: gOpts.sortType,
|
||||
hiddenfiles: gOpts.hiddenfiles,
|
||||
ignorecase: gOpts.ignorecase,
|
||||
ignoredia: gOpts.ignoredia,
|
||||
}
|
||||
|
||||
nav.checkDir(d)
|
||||
|
||||
go func() {
|
||||
d := newDir(path)
|
||||
d.sort()
|
||||
d.ind, d.pos = 0, 0
|
||||
nav.dirChan <- d
|
||||
}()
|
||||
return d
|
||||
}
|
||||
|
||||
func (nav *nav) loadDir(path string) *dir {
|
||||
if gOpts.dircache {
|
||||
d, ok := nav.dirCache[path]
|
||||
if !ok {
|
||||
d = nav.loadDirInternal(path)
|
||||
nav.dirCache[path] = d
|
||||
return d
|
||||
}
|
||||
|
||||
nav.checkDir(d)
|
||||
|
||||
return d
|
||||
} else {
|
||||
return nav.loadDirInternal(path)
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) checkDir(dir *dir) {
|
||||
s, err := os.Stat(dir.path)
|
||||
if err != nil {
|
||||
|
||||
@@ -30,6 +30,7 @@ type sortType struct {
|
||||
var gOpts struct {
|
||||
anchorfind bool
|
||||
autoquit bool
|
||||
dircache bool
|
||||
dircounts bool
|
||||
dironly bool
|
||||
drawbox bool
|
||||
@@ -74,6 +75,7 @@ var gOpts struct {
|
||||
func init() {
|
||||
gOpts.anchorfind = true
|
||||
gOpts.autoquit = false
|
||||
gOpts.dircache = true
|
||||
gOpts.dircounts = false
|
||||
gOpts.dironly = false
|
||||
gOpts.drawbox = false
|
||||
|
||||
Reference in new issue
Block a user