pull/268/head
Anton Medvedev 9 months ago
parent 0f4f355f7e
commit 3969fc3f0f
No known key found for this signature in database

@ -80,11 +80,11 @@ func init() {
key.WithHelp("", "collapse"),
),
ExpandRecursively: key.NewBinding(
key.WithKeys("L"),
key.WithKeys("L", "shift+right"),
key.WithHelp("", "expand recursively"),
),
CollapseRecursively: key.NewBinding(
key.WithKeys("H"),
key.WithKeys("H", "shift+left"),
key.WithHelp("", "collapse recursively"),
),
ExpandAll: key.NewBinding(

@ -194,6 +194,28 @@ func (m *model) handleKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
case key.Matches(msg, keyMap.Expand):
m.cursorPointsTo().expand()
case key.Matches(msg, keyMap.CollapseRecursively):
n := m.cursorPointsTo()
if n.hasChildren() {
n.collapseRecursively()
}
case key.Matches(msg, keyMap.ExpandRecursively):
n := m.cursorPointsTo()
if n.hasChildren() {
n.expandRecursively()
}
case key.Matches(msg, keyMap.CollapseAll):
m.top.collapseRecursively()
m.cursor = 0
m.head = m.top
case key.Matches(msg, keyMap.ExpandAll):
at := m.cursorPointsTo()
m.top.expandRecursively()
m.selectNode(at)
}
return m, nil
}

@ -92,6 +92,22 @@ func (n *node) collapse() *node {
return n
}
func (n *node) collapseRecursively() {
var at *node
if n.isCollapsed() {
at = n.collapsed
} else {
at = n.next
}
for at != nil && at != n.end {
if at.hasChildren() {
at.collapseRecursively()
at.collapse()
}
at = at.next
}
}
func (n *node) expand() {
if n.isCollapsed() {
if n.next != nil {
@ -101,3 +117,11 @@ func (n *node) expand() {
n.collapsed = nil
}
}
func (n *node) expandRecursively() {
at := n
for at != nil && at != n.end {
at.expand()
at = at.next
}
}

Loading…
Cancel
Save