Skip to content

Commit 7ac0e1a

Browse files
committed
fix(Tree): Fix removeFromIndex to remove the entire subtree
instead of just the ID of the item that was passed Signed-off-by: Marcel Klehr <[email protected]>
1 parent 2e5afd1 commit 7ac0e1a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/lib/Tree.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ export class Folder<L extends TItemLocation> {
602602
}
603603

604604
/**
605-
* Update the index by removing the given item (this method should be called on the root folder)
605+
* Update the index by removing the given item and its children (this method should be called on the root folder)
606606
*/
607607
removeFromIndex(item: TItem<L>) {
608608
if (!item) return
@@ -613,7 +613,16 @@ export class Folder<L extends TItemLocation> {
613613
if (item.parentId) {
614614
let parentFolder = this.index.folder[item.parentId]
615615
while (parentFolder && this.index.folder[parentFolder.parentId] !== parentFolder) {
616-
delete parentFolder.index[item.type][item.id]
616+
if (item instanceof Bookmark) {
617+
delete parentFolder.index[item.type][item.id]
618+
} else {
619+
for (const folderId in item.index.folder) {
620+
delete parentFolder.index.folder.folder[folderId]
621+
}
622+
for (const bookmarkId in item.index.bookmark) {
623+
delete parentFolder.index.folder.bookmark[bookmarkId]
624+
}
625+
}
617626
parentFolder = this.index.folder[parentFolder.parentId]
618627
}
619628
}

0 commit comments

Comments
 (0)