Fix three layers of safeguards to ensure node doesn't become it's own parent
This commit is contained in:
parent
960c9e2625
commit
edd3d11b09
3 changed files with 143 additions and 7 deletions
|
|
@ -424,6 +424,9 @@ export class Node {
|
|||
return this._parent
|
||||
}//}}}
|
||||
moveToParent(newParentUUID) {// {{{
|
||||
if (this.UUID === newParentUUID)
|
||||
throw new Error("New parent UUID is the same as node UUID. Can't be your own parent.")
|
||||
|
||||
this.ParentUUID = newParentUUID
|
||||
this.data.ParentUUID = newParentUUID
|
||||
this._modified = true
|
||||
|
|
|
|||
|
|
@ -598,15 +598,25 @@ export class N2TreeNode extends CustomHTMLElement {
|
|||
e.preventDefault()
|
||||
}// }}}
|
||||
async dragDrop(e) {// {{{
|
||||
e.stopPropagation()
|
||||
const sourceNode = _app.dragIcon.getSource()
|
||||
await _app.moveNode(sourceNode.node, this.node.UUID)
|
||||
try {
|
||||
e.stopPropagation()
|
||||
const sourceNode = _app.dragIcon.getSource()
|
||||
|
||||
_app.sidebar.setNodeExpanded(this, true)
|
||||
await this.render(true, true)
|
||||
await sourceNode.render(true, true)
|
||||
// Abort if user drops the node back on itself.
|
||||
if (sourceNode.node.UUID === this.node.UUID)
|
||||
return
|
||||
|
||||
this.dragLeave(e)
|
||||
await _app.moveNode(sourceNode.node, this.node.UUID)
|
||||
|
||||
_app.sidebar.setNodeExpanded(this, true)
|
||||
await this.render(true, true)
|
||||
await sourceNode.render(true, true)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
alert(e)
|
||||
} finally {
|
||||
this.dragLeave(e)
|
||||
}
|
||||
}// }}}
|
||||
dragEnter(e) {// {{{
|
||||
const targetNode = e.target.closest('n2-treenode')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue