Fixed left node navigation, down of bottom of tree
This commit is contained in:
parent
d5ffd4fb0a
commit
8192f49558
2 changed files with 31 additions and 4 deletions
1
node.go
1
node.go
|
@ -325,6 +325,7 @@ func generateOneTestNode(parentUUID, parentPath string) (hash, name string, err
|
|||
row = db.QueryRow(query, sqlParentUUID, parentPath)
|
||||
err = row.Scan(&hash, &name)
|
||||
if err != nil {
|
||||
Log.Error("generate", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -175,19 +175,34 @@ class Tree extends Component {
|
|||
this.getNodeExpanded(UUID)
|
||||
this.expandedNodes[UUID].value = value
|
||||
}//}}}
|
||||
getParentNodeWithNextSibling(node) {//{{{
|
||||
getParentWithNextSibling(node) {//{{{
|
||||
let currNode = node
|
||||
while (currNode !== null && currNode.UUID !== ROOT_NODE && currNode.getSiblingAfter() === null) {
|
||||
currNode = currNode.getParent()
|
||||
}
|
||||
return currNode?.getSiblingAfter()
|
||||
}//}}}
|
||||
getLastExpandedNode(node) {//{{{
|
||||
let currNode = node
|
||||
while (this.getNodeExpanded(currNode.UUID) && currNode.hasChildren()) {
|
||||
currNode = currNode.Children[currNode.Children.length - 1]
|
||||
}
|
||||
return currNode
|
||||
}//}}}
|
||||
|
||||
async keyHandler(event) {//{{{
|
||||
let handled = true
|
||||
const n = this.selectedNode
|
||||
const Space = ' '
|
||||
|
||||
switch (event.key) {
|
||||
// Space is toggling expansion.
|
||||
case Space:
|
||||
case 'Enter':
|
||||
const expanded = this.getNodeExpanded(n.UUID)
|
||||
this.setNodeExpanded(n.UUID, !expanded)
|
||||
break
|
||||
|
||||
case 'j':
|
||||
case 'ArrowDown':
|
||||
await this.navigateDown(this.selectedNode)
|
||||
|
@ -209,6 +224,7 @@ class Tree extends Component {
|
|||
break
|
||||
|
||||
default:
|
||||
// nonsole.log(event.key)
|
||||
handled = false
|
||||
}
|
||||
|
||||
|
@ -229,6 +245,14 @@ class Tree extends Component {
|
|||
return
|
||||
}
|
||||
|
||||
const siblingBefore = n.getSiblingBefore()
|
||||
const siblingExpanded = this.getNodeExpanded(siblingBefore?.UUID)
|
||||
if (siblingBefore !== null && siblingExpanded && siblingBefore.hasChildren()) {
|
||||
const siblingAbove = this.getLastExpandedNode(siblingBefore)
|
||||
await _notes2.current.goToNode(siblingAbove?.UUID, true, true)
|
||||
return
|
||||
}
|
||||
|
||||
await _notes2.current.goToNode(n.getSiblingBefore()?.UUID, true, true)
|
||||
}//}}}
|
||||
async navigateRight(n) {//{{{
|
||||
|
@ -246,7 +270,7 @@ class Tree extends Component {
|
|||
}
|
||||
|
||||
if (n.isLastSibling()) {
|
||||
const nextNode = this.getParentNodeWithNextSibling(n)
|
||||
const nextNode = this.getParentWithNextSibling(n)
|
||||
await _notes2.current.goToNode(nextNode?.UUID, true, true)
|
||||
return
|
||||
}
|
||||
|
@ -284,7 +308,7 @@ class Tree extends Component {
|
|||
// Last node, not expanded, so it matters not whether it has children or not.
|
||||
// Traverse upward to nearest parent with next sibling.
|
||||
if (!nodeExpanded && n.isLastSibling()) {
|
||||
const wantedNode = this.getParentNodeWithNextSibling(n)
|
||||
const wantedNode = this.getParentWithNextSibling(n)
|
||||
if (wantedNode?.UUID === ROOT_NODE)
|
||||
return
|
||||
await _notes2.current.goToNode(wantedNode?.UUID, true, true)
|
||||
|
@ -292,13 +316,15 @@ class Tree extends Component {
|
|||
}
|
||||
|
||||
if (nodeExpanded && n.isLastSibling() && !n.hasChildren()) {
|
||||
const wantedNode = this.getParentNodeWithNextSibling(n)
|
||||
const wantedNode = this.getParentWithNextSibling(n)
|
||||
await _notes2.current.goToNode(wantedNode?.UUID, true, true)
|
||||
return
|
||||
}
|
||||
// Node not expanded. Go to this node's next sibling.
|
||||
// GoToNode will abort if given null.
|
||||
if (!nodeExpanded || !n.hasChildren()) {
|
||||
if (n.getSiblingAfter()?.UUID === ROOT_NODE)
|
||||
return
|
||||
await _notes2.current.goToNode(n.getSiblingAfter()?.UUID, true, true)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue