From 350a24badd19e41e09d036985ac52c39042c22a1 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sun, 19 May 2019 20:16:24 -0400 Subject: [PATCH] Fix multi-root traversal --- tree.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tree.go b/tree.go index 9cef87e..f55ee9a 100644 --- a/tree.go +++ b/tree.go @@ -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) }