Skip to content

Commit 733e8d6

Browse files
authored
refactor: remove init flag (gokcehan#2313)
* refactor: remove init flag * fix bugs * cleanup of `addcustominfo` * use `getDir` for accessing directories from cache * Avoid trimming `addcustominfo` value
1 parent 57f6ade commit 733e8d6

File tree

4 files changed

+203
-441
lines changed

4 files changed

+203
-441
lines changed

app.go

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,8 @@ func (app *app) loop() {
296296
}
297297
}
298298

299-
wd, err := os.Getwd()
300-
if err != nil {
301-
log.Printf("getting current directory: %s", err)
302-
}
303-
304-
app.nav.updateDirs(wd)
299+
app.nav.loadDirs()
305300
app.nav.addJumpList()
306-
app.nav.init = true
307301

308302
if gSelect != "" {
309303
go func() {
@@ -393,6 +387,11 @@ func (app *app) loop() {
393387
}
394388
app.ui.draw(app.nav)
395389
case d := <-app.nav.dirChan:
390+
var oldCurrPath string
391+
if curr := app.nav.currFile(); curr != nil {
392+
oldCurrPath = curr.path
393+
}
394+
396395
prev, ok := app.nav.dirCache[d.path]
397396
if ok {
398397
d.ind = prev.ind
@@ -405,21 +404,9 @@ func (app *app) loop() {
405404
}
406405
app.nav.dirCache[d.path] = d
407406

408-
var oldCurrPath string
409-
if curr, err := app.nav.currFile(); err == nil {
410-
oldCurrPath = curr.path
411-
}
412-
413-
for i := range app.nav.dirs {
414-
if app.nav.dirs[i].path == d.path {
415-
app.nav.dirs[i] = d
416-
}
417-
}
418-
419407
app.nav.position()
420408

421-
curr, err := app.nav.currFile()
422-
if err == nil {
409+
if curr := app.nav.currFile(); curr != nil {
423410
if curr.path != oldCurrPath {
424411
app.ui.loadFile(app, true)
425412
}
@@ -441,8 +428,7 @@ func (app *app) loop() {
441428
case r := <-app.nav.regChan:
442429
app.nav.regCache[r.path] = r
443430

444-
curr, err := app.nav.currFile()
445-
if err == nil {
431+
if curr := app.nav.currFile(); curr != nil {
446432
if r.path == curr.path {
447433
app.ui.sxScreen.forceClear = true
448434
if gOpts.preload && r.volatile {
@@ -485,9 +471,7 @@ func (app *app) loop() {
485471
deletePathRecursive(app.nav.dirCache, path)
486472
currPath := app.nav.currDir().path
487473
if currPath == path || strings.HasPrefix(currPath, path+string(filepath.Separator)) {
488-
if wd, err := os.Getwd(); err == nil {
489-
app.nav.updateDirs(wd)
490-
}
474+
app.nav.loadDirs()
491475
}
492476
case ev := <-app.ui.evChan:
493477
e := app.ui.readEvent(ev, app.nav)

0 commit comments

Comments
 (0)