pull/268/head
Anton Medvedev 9 months ago
parent bf6a7f550e
commit 7c7ee00be3
No known key found for this signature in database

@ -96,11 +96,11 @@ func init() {
key.WithHelp("", "collapse all"),
),
NextSibling: key.NewBinding(
key.WithKeys("J"),
key.WithKeys("J", "shift+down"),
key.WithHelp("", "next sibling"),
),
PrevSibling: key.NewBinding(
key.WithKeys("K"),
key.WithKeys("K", "shift+up"),
key.WithHelp("", "previous sibling"),
),
ToggleWrap: key.NewBinding(

@ -75,6 +75,17 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.MouseWheelDown:
m.down()
case tea.MouseLeft:
if msg.Y < m.viewHeight() {
m.cursor = msg.Y
node := m.cursorPointsTo()
if node.isCollapsed() {
node.expand()
} else {
node.collapse()
}
}
}
case tea.KeyMsg:
@ -128,8 +139,28 @@ func (m *model) handleKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.scrollIntoView()
m.cursor = m.visibleLines() - 1
case key.Matches(msg, keyMap.NextSibling):
pointsTo := m.cursorPointsTo()
var nextSibling *node
if pointsTo.end != nil && pointsTo.end.next != nil {
nextSibling = pointsTo.end.next
} else {
nextSibling = pointsTo.next
}
if nextSibling != nil {
if m.nodeInsideView(nextSibling) {
m.selectNodeInView(nextSibling)
} else {
m.cursor = 0
m.head = nextSibling
m.scrollIntoView()
}
}
case key.Matches(msg, keyMap.PrevSibling):
case key.Matches(msg, keyMap.Collapse):
node := m.cursorPointsTo().collapse()
node := m.cursorPointsTo().collapseThisOrParent()
if m.nodeInsideView(node) {
m.selectNodeInView(node)
m.scrollIntoView()

@ -35,20 +35,25 @@ func (n *node) append(child *node) {
}
}
func (n *node) collapse() *node {
func (n *node) collapseThisOrParent() *node {
if n.end == nil || n.isCollapsed() {
if n.parent() != nil {
return n.parent().collapse()
}
return n
} else {
}
return n.collapse()
}
func (n *node) collapse() *node {
if n.end != nil {
n.collapsed = n.next
n.next = n.end.next
if n.next != nil {
n.next.prev = n
}
return n
}
return n
}
func (n *node) isCollapsed() bool {

Loading…
Cancel
Save