diff --git a/tree.go b/tree.go index d6fcc8f..2e7cae2 100644 --- a/tree.go +++ b/tree.go @@ -61,9 +61,16 @@ func (tree *TreeWidget) SelectNext() { tree.selectedNode = tree.selectedNode.children[0] } else if tree.selectedNode.next != nil { tree.selectedNode = tree.selectedNode.next - } else if tree.selectedNode.next == nil && tree.selectedNode.parent != nil && tree.selectedNode.parent.next != nil { - // Go up to the next adjacent node to a parent - tree.selectedNode = tree.selectedNode.parent.next + } else if tree.selectedNode.next == nil && tree.selectedNode.parent != nil { + cursorNode := tree.selectedNode.parent + // Go up to the next adjacent node to the first parent node with another node adjacent to it. + for cursorNode != nil { + if cursorNode.next != nil { + tree.selectedNode = cursorNode.next + return + } + cursorNode = cursorNode.parent + } } }