Fixed left node navigation, down of bottom of tree

This commit is contained in:
Magnus Åhall 2025-02-09 10:42:03 +01:00
parent d5ffd4fb0a
commit 8192f49558
2 changed files with 31 additions and 4 deletions

View file

@ -325,6 +325,7 @@ func generateOneTestNode(parentUUID, parentPath string) (hash, name string, err
row = db.QueryRow(query, sqlParentUUID, parentPath) row = db.QueryRow(query, sqlParentUUID, parentPath)
err = row.Scan(&hash, &name) err = row.Scan(&hash, &name)
if err != nil { if err != nil {
Log.Error("generate", "error", err)
return return
} }

View file

@ -175,19 +175,34 @@ class Tree extends Component {
this.getNodeExpanded(UUID) this.getNodeExpanded(UUID)
this.expandedNodes[UUID].value = value this.expandedNodes[UUID].value = value
}//}}} }//}}}
getParentNodeWithNextSibling(node) {//{{{ getParentWithNextSibling(node) {//{{{
let currNode = node let currNode = node
while (currNode !== null && currNode.UUID !== ROOT_NODE && currNode.getSiblingAfter() === null) { while (currNode !== null && currNode.UUID !== ROOT_NODE && currNode.getSiblingAfter() === null) {
currNode = currNode.getParent() currNode = currNode.getParent()
} }
return currNode?.getSiblingAfter() 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) {//{{{ async keyHandler(event) {//{{{
let handled = true let handled = true
const n = this.selectedNode const n = this.selectedNode
const Space = ' '
switch (event.key) { 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 'j':
case 'ArrowDown': case 'ArrowDown':
await this.navigateDown(this.selectedNode) await this.navigateDown(this.selectedNode)
@ -209,6 +224,7 @@ class Tree extends Component {
break break
default: default:
// nonsole.log(event.key)
handled = false handled = false
} }
@ -229,6 +245,14 @@ class Tree extends Component {
return 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) await _notes2.current.goToNode(n.getSiblingBefore()?.UUID, true, true)
}//}}} }//}}}
async navigateRight(n) {//{{{ async navigateRight(n) {//{{{
@ -246,7 +270,7 @@ class Tree extends Component {
} }
if (n.isLastSibling()) { if (n.isLastSibling()) {
const nextNode = this.getParentNodeWithNextSibling(n) const nextNode = this.getParentWithNextSibling(n)
await _notes2.current.goToNode(nextNode?.UUID, true, true) await _notes2.current.goToNode(nextNode?.UUID, true, true)
return return
} }
@ -284,7 +308,7 @@ class Tree extends Component {
// Last node, not expanded, so it matters not whether it has children or not. // Last node, not expanded, so it matters not whether it has children or not.
// Traverse upward to nearest parent with next sibling. // Traverse upward to nearest parent with next sibling.
if (!nodeExpanded && n.isLastSibling()) { if (!nodeExpanded && n.isLastSibling()) {
const wantedNode = this.getParentNodeWithNextSibling(n) const wantedNode = this.getParentWithNextSibling(n)
if (wantedNode?.UUID === ROOT_NODE) if (wantedNode?.UUID === ROOT_NODE)
return return
await _notes2.current.goToNode(wantedNode?.UUID, true, true) await _notes2.current.goToNode(wantedNode?.UUID, true, true)
@ -292,13 +316,15 @@ class Tree extends Component {
} }
if (nodeExpanded && n.isLastSibling() && !n.hasChildren()) { if (nodeExpanded && n.isLastSibling() && !n.hasChildren()) {
const wantedNode = this.getParentNodeWithNextSibling(n) const wantedNode = this.getParentWithNextSibling(n)
await _notes2.current.goToNode(wantedNode?.UUID, true, true) await _notes2.current.goToNode(wantedNode?.UUID, true, true)
return return
} }
// Node not expanded. Go to this node's next sibling. // Node not expanded. Go to this node's next sibling.
// GoToNode will abort if given null. // GoToNode will abort if given null.
if (!nodeExpanded || !n.hasChildren()) { if (!nodeExpanded || !n.hasChildren()) {
if (n.getSiblingAfter()?.UUID === ROOT_NODE)
return
await _notes2.current.goToNode(n.getSiblingAfter()?.UUID, true, true) await _notes2.current.goToNode(n.getSiblingAfter()?.UUID, true, true)
return return
} }