Fix multi-root traversal

master
Nick Krichevsky 2019-05-19 20:16:24 -04:00
parent 456f817d67
commit 350a24badd
1 changed files with 7 additions and 3 deletions

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
func (tree *TreeWidget) AddRootNode(node *Node) {
tree.rootNodes = append(tree.rootNodes, node)
if len(tree.rootNodes) == 1 {
tree.selectedNode = node.children[0]
if len(tree.rootNodes) > 0 {
node.prev = tree.rootNodes[len(tree.rootNodes)-1]
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)
}