diff --git a/internal/ui/service/savepath/savepath.go b/internal/ui/service/savepath/savepath.go index f29db90..6e7a1f5 100644 --- a/internal/ui/service/savepath/savepath.go +++ b/internal/ui/service/savepath/savepath.go @@ -91,10 +91,13 @@ func Save() { } func Update(b traverse.Breadcrumber, expanded bool) { - if expanded { - var path = traverse.TryID(b) - var node = paths + var path = traverse.TryID(b) + var node = paths + // TODO: this doesn't actually account for paths that no longer exist, but + // it's complex to check. + + if expanded { // Descend and initialize. for i := 0; i < len(path); i++ { ch, ok := node[path[i]] @@ -106,7 +109,20 @@ func Update(b traverse.Breadcrumber, expanded bool) { node = ch } } else { + for i := 0; i < len(path); i++ { + ch, ok := node[path[i]] + if !ok { + // We can't find anything. + return + } + if i == len(path)-1 { + // We're at the last node, so we can delete things now. + delete(node, path[i]) + } + + node = ch + } } Save() diff --git a/internal/ui/service/session/server/server.go b/internal/ui/service/session/server/server.go index d6f9d39..7dd6d6f 100644 --- a/internal/ui/service/session/server/server.go +++ b/internal/ui/service/session/server/server.go @@ -392,6 +392,9 @@ func (r *ServerRow) SetRevealChild(reveal bool) { // Actually reveal the children. r.childrev.SetRevealChild(reveal) + // Save the path. + savepath.Update(r, reveal) + // If this isn't a reveal, then we don't need to load. if !reveal { return @@ -401,9 +404,6 @@ func (r *ServerRow) SetRevealChild(reveal bool) { // to call Servers on this. Now, we already know that there are hollow // servers in the children container. r.children.LoadAll() - - // Save the path. - savepath.Update(r, reveal) } // GetRevealChild returns whether or not the server list is expanded, or always