Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(tree): keep the hidden subtree out of delete navigation
Elian Doran831539253599
diff --git a/apps/client/src/services/branches.spec.ts b/apps/client/src/services/branches.spec.tsindex b1542e2a46..a04885e4f2 100644--- a/apps/client/src/services/branches.spec.ts+++ b/apps/client/src/services/branches.spec.ts@@ -382,6 +382,21 @@ describe("activateNeighbouringNotePath (via deleteNotes navigation)", () => {expect(setNote).toHaveBeenCalledWith(`root/${p}/clC`);});+ it("never activates the hidden subtree when deleting the last child of root", async () => {+ const root = froca.getNoteFromCache("root");+ for (const noteId of ["rootFirst", "rootLast", "_hidden"]) {+ buildNote({ id: noteId, title: noteId });+ makeBranch(`root_${noteId}`, noteId, "root");+ root?.addChild(noteId, `root_${noteId}`, false);+ froca.getNoteFromCache(noteId)?.addParent("root", `root_${noteId}`, false);+ }+ expect(root?.getChildNoteIds()).toEqual(["rootFirst", "rootLast", "_hidden"]);++ const setNote = confirmDeletion(["root", "rootLast"]);+ await branches.deleteNotes(["root_rootLast"]);+ expect(setNote).toHaveBeenCalledWith("root/rootFirst");+ });+it("falls back to the parent when its children are not loaded in froca", async () => {const note = buildNote({ title: "Lonely" });makeBranch("lonelyBranch", note.noteId, "root");diff --git a/apps/client/src/services/branches.ts b/apps/client/src/services/branches.tsindex 997e2d0a58..b1a41f2297 100644--- a/apps/client/src/services/branches.ts+++ b/apps/client/src/services/branches.ts@@ -192,7 +192,7 @@ async function activateNeighbouringNotePath(branchIdsToDelete: string[], deleteA/*** Finds the child of `parentNoteId` closest to `noteId` that is still there once the given branches* are deleted: the next sibling, else the previous one. Archived siblings are skipped, since the- * tree can be set to hide them.+ * tree can be set to hide them, and so is `_hidden`, which the tree hides under root.*/function findSurvivingSibling(parentNoteId: string,@@ -218,6 +218,7 @@ function findSurvivingSibling(const survives = (branch: FBranch) =>!branchIdsToDelete.includes(branch.branchId)&& !(deleteAllClones && deletedNoteIds.has(branch.noteId))+ && branch.noteId !== "_hidden"&& !froca.getNoteFromCache(branch.noteId)?.isArchived;const candidates = [diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.tsindex 2fd46b4966..30c0b3f101 100644--- a/apps/client/src/widgets/note_tree.ts+++ b/apps/client/src/widgets/note_tree.ts@@ -1360,7 +1360,10 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {for (const node of this.getNodesByBranch(branchRow)) {if (node.isActive()) {if (allBranchesDeleted) {- const newActiveNode = node.getNextSibling() || node.getPrevSibling() || node.getParent();+ // `_hidden` stays in the tree under root, hidden only by CSS.+ const newActiveNode = [+ node.getNextSibling(), node.getPrevSibling(), node.getParent()+ ].find((candidate) => candidate && candidate.data.noteId !== "_hidden");if (newActiveNode) {newActiveNode.setActive(true, { noEvents: true, noFocus: true });