From 1c9d9ebea256175ee48e1f5ffc40dbcc4f008ead Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Sun, 10 Sep 2023 16:03:51 +0200 Subject: [PATCH] wip --- new/main.go | 4 ++-- new/node.go | 18 ++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/new/main.go b/new/main.go index f504475..a5a2040 100644 --- a/new/main.go +++ b/new/main.go @@ -179,7 +179,7 @@ func (m *model) handleKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) { } case key.Matches(msg, keyMap.Collapse): - node := m.cursorPointsTo().collapseThisOrParent() + node := m.cursorPointsTo().collapse() if m.nodeInsideView(node) { m.selectNodeInView(node) m.scrollIntoView() @@ -215,7 +215,7 @@ func (m *model) down() { } if m.cursor >= m.viewHeight() { m.cursor = m.viewHeight() - 1 - if m.head.next != nil && !n.atEnd() { + if m.head.next != nil && n.next != nil { m.head = m.head.next } } diff --git a/new/node.go b/new/node.go index ea34e4d..47d43b4 100644 --- a/new/node.go +++ b/new/node.go @@ -11,6 +11,10 @@ type node struct { comma bool } +func (n *node) hasChildren() bool { + return n.end != nil +} + func (n *node) parent() *node { if n.directParent == nil { return nil @@ -35,16 +39,6 @@ func (n *node) append(child *node) { } } -func (n *node) collapseThisOrParent() *node { - if n.end == nil || n.isCollapsed() { - if n.parent() != nil { - return n.parent().collapseThisOrParent() - } - return n - } - return n.collapse() -} - func (n *node) collapse() *node { if n.end != nil { n.collapsed = n.next @@ -69,7 +63,3 @@ func (n *node) expand() { n.collapsed = nil } } - -func (n *node) atEnd() bool { - return n.next == nil -}