Skip to content

Commit

Permalink
bug fix. When promoting to top level previously wasn't updating previ…
Browse files Browse the repository at this point in the history
…ous parent correctly which could lead to data loss if that parent was then deleted
  • Loading branch information
tconfrey committed Oct 15, 2024
1 parent d243cfc commit a1344a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions app/BTNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,17 @@ class BTNode {
if (newP == this._id) throw "reparentNode: setting self to parent!";

const oldP = this.parentId;
if (!oldP || !newP) return; // no parent to remove from
if (!oldP && !newP) return; // nothing to do
if (oldP === newP) {
// Special case: new parent is the same as the old parent
const parentNode = AllNodes[oldP];
const oldIndex = parentNode.childIds.indexOf(this._id);
arrayMoveElt(parentNode.childIds, oldIndex, index);
} else {
AllNodes[oldP].removeChild(this.id);
// either old or newP might be null, ie at top level
oldP && AllNodes[oldP].removeChild(this.id);
this.parentId = newP;
AllNodes[newP].addChild(this.id, index);
newP && AllNodes[newP].addChild(this.id, index);
}
}

Expand Down
7 changes: 4 additions & 3 deletions versions/1.0.3/app/BTNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,17 @@ class BTNode {
if (newP == this._id) throw "reparentNode: setting self to parent!";

const oldP = this.parentId;
if (!oldP || !newP) return; // no parent to remove from
if (!oldP && !newP) return; // nothing to do
if (oldP === newP) {
// Special case: new parent is the same as the old parent
const parentNode = AllNodes[oldP];
const oldIndex = parentNode.childIds.indexOf(this._id);
arrayMoveElt(parentNode.childIds, oldIndex, index);
} else {
AllNodes[oldP].removeChild(this.id);
// either old or newP might be null, ie at top level
oldP && AllNodes[oldP].removeChild(this.id);
this.parentId = newP;
AllNodes[newP].addChild(this.id, index);
newP && AllNodes[newP].addChild(this.id, index);
}
}

Expand Down

0 comments on commit a1344a9

Please sign in to comment.