Fix multi-root traversal

This commit is contained in:
Nick Krichevsky 2019-05-19 20:16:24 -04:00
parent 456f817d67
commit 350a24badd

10
tree.go
View file

@ -49,10 +49,14 @@ func (tree *TreeWidget) Draw(buffer *termui.Buffer) {
// AddRootNode adds a new top-level node to the tree // AddRootNode adds a new top-level node to the tree
func (tree *TreeWidget) AddRootNode(node *Node) { func (tree *TreeWidget) AddRootNode(node *Node) {
tree.rootNodes = append(tree.rootNodes, node) if len(tree.rootNodes) > 0 {
if len(tree.rootNodes) == 1 { node.prev = tree.rootNodes[len(tree.rootNodes)-1]
tree.selectedNode = node.children[0] node.prev.next = node
} else if len(tree.rootNodes) == 0 {
// If this is our first node, then we need to mark this as the current node
tree.selectedNode = node
} }
tree.rootNodes = append(tree.rootNodes, node)
node.setTree(tree) node.setTree(tree)
} }