diff options
-rw-r--r-- | filetree/tree.go | 5 | ||||
-rw-r--r-- | ui/filetreeview.go | 17 |
2 files changed, 17 insertions, 5 deletions
diff --git a/filetree/tree.go b/filetree/tree.go index 6ba0703..83532d2 100644 --- a/filetree/tree.go +++ b/filetree/tree.go @@ -209,9 +209,8 @@ func (tree *FileTree) MarkRemoved(path string) error { } func StackRange(trees []*FileTree, index int) *FileTree { - // TMP TMP TMP: TODO: later change the index of both of these to 0 - tree := trees[1].Copy() - for idx := 1; idx <= index; idx++ { + tree := trees[0].Copy() + for idx := 0; idx <= index; idx++ { tree.Stack(trees[idx]) } return tree diff --git a/ui/filetreeview.go b/ui/filetreeview.go index 097a4d3..2516acd 100644 --- a/ui/filetreeview.go +++ b/ui/filetreeview.go @@ -55,13 +55,26 @@ func (view *FileTreeView) Setup(v *gocui.View) error { } func (view *FileTreeView) setLayer(layerIndex int) error { - view.Tree = filetree.StackRange(view.RefTrees, layerIndex-1) - view.Tree.Compare(view.RefTrees[layerIndex]) + newTree := filetree.StackRange(view.RefTrees, layerIndex-1) + newTree.Compare(view.RefTrees[layerIndex]) + + visitor := func(node *filetree.FileNode) error { + if node.Collapsed { + newNode, err := newTree.GetNode(node.Path()) + if err == nil { + newNode.Collapsed = true + } + } + return nil + } + view.Tree.Visit(visitor) + // v, _ := view.gui.View("debug") // v.Clear() // _, _ = fmt.Fprintln(v, view.RefTrees[layerIndex]) view.view.SetCursor(0, 0) view.TreeIndex = 0 + view.Tree = newTree return view.Render() } |