Better fix for reload if current path is renamed (#2005)
This commit is contained in:
1 parent
320322c5cd
commit
249264b4cd
3 files changed
+26
-6
No files matched your search
@@ -466,13 +466,20 @@ func (app *app) loop() {
|
||||
}
|
||||
app.ui.draw(app.nav)
|
||||
case path := <-app.nav.delChan:
|
||||
delete(app.nav.dirCache, path)
|
||||
delete(app.nav.regCache, path)
|
||||
|
||||
delete(app.nav.selections, path)
|
||||
deletePathRecusrive(app.nav.selections, path)
|
||||
if len(app.nav.selections) == 0 {
|
||||
app.nav.selectionInd = 0
|
||||
}
|
||||
|
||||
deletePathRecusrive(app.nav.regCache, path)
|
||||
|
||||
deletePathRecusrive(app.nav.dirCache, path)
|
||||
currPath := app.nav.currDir().path
|
||||
if currPath == path || strings.HasPrefix(currPath, path+string(filepath.Separator)) {
|
||||
if wd, err := os.Getwd(); err == nil {
|
||||
app.nav.getDirs(wd)
|
||||
}
|
||||
}
|
||||
case ev := <-app.ui.evChan:
|
||||
e := app.ui.readEvent(ev, app.nav)
|
||||
if e == nil {
|
||||
|
||||
@@ -378,6 +378,19 @@ func makeCollator(localeStr string, opts ...collate.Option) (*collate.Collator,
|
||||
return collate.New(localeTag, opts...), nil
|
||||
}
|
||||
|
||||
// This function deletes entries from a map if the key is either the given path
|
||||
// or a subpath of it.
|
||||
// This is useful for clearing cached data when a directory is moved or deleted.
|
||||
func deletePathRecusrive[T any](m map[string]T, path string) {
|
||||
delete(m, path)
|
||||
prefix := path + string(filepath.Separator)
|
||||
for k := range m {
|
||||
if strings.HasPrefix(k, prefix) {
|
||||
delete(m, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We don't need no generic code
|
||||
// We don't need no type control
|
||||
// No dark templates in compiler
|
||||
|
||||
@@ -1488,8 +1488,8 @@ func (nav *nav) rename() error {
|
||||
// existed and was deleted. In this case the cache entries should be deleted
|
||||
// before loading newPath to prevent displaying a stale preview. However,
|
||||
// this clears only the current instance of lf, and not any other instances.
|
||||
delete(nav.regCache, newPath)
|
||||
delete(nav.dirCache, newPath)
|
||||
deletePathRecusrive(nav.regCache, newPath)
|
||||
deletePathRecusrive(nav.dirCache, newPath)
|
||||
dir := nav.loadDir(filepath.Dir(newPath))
|
||||
|
||||
if dir.loading {
|
||||
|
||||
Reference in new issue
Block a user