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): deleting ancestor of the current note doesn't correctly navigate
Elian Doran14bb068626e9
diff --git a/apps/client/src/services/branches.ts b/apps/client/src/services/branches.tsindex 8f31060242..15d24a10d7 100644--- a/apps/client/src/services/branches.ts+++ b/apps/client/src/services/branches.ts@@ -120,7 +120,7 @@ async function deleteNotes(branchIdsToDelete: string[], forceDeleteAllClones = fif (moveToParent) {try {- await activateParentNotePath();+ await activateParentNotePath(branchIdsToDelete);} catch (e) {console.error(e);}@@ -152,13 +152,28 @@ async function deleteNotes(branchIdsToDelete: string[], forceDeleteAllClones = freturn true;}-async function activateParentNotePath() {- // this is not perfect, maybe we should find the next/previous sibling, but that's more complex+async function activateParentNotePath(branchIdsToDelete: string[]) {const activeContext = appContext.tabManager.getActiveContext();- const parentNotePathArr = activeContext?.notePathArray.slice(0, -1);+ const activeNotePath = activeContext?.notePathArray ?? [];- if (parentNotePathArr && parentNotePathArr.length > 0) {- activeContext?.setNote(parentNotePathArr.join("/"));+ // Find the deleted branch that appears earliest in the active note's path+ let earliestIndex = activeNotePath.length;+ for (const branchId of branchIdsToDelete) {+ const branch = froca.getBranch(branchId);+ if (branch) {+ const index = activeNotePath.indexOf(branch.noteId);+ if (index !== -1 && index < earliestIndex) {+ earliestIndex = index;+ }+ }+ }++ // Navigate to the parent of the highest deleted ancestor+ if (earliestIndex < activeNotePath.length) {+ const parentPath = activeNotePath.slice(0, earliestIndex);+ if (parentPath.length > 0) {+ await activeContext?.setNote(parentPath.join("/"));+ }}}diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.tsindex 2617be3e01..5c2aadb1ea 100644--- a/apps/client/src/widgets/note_tree.ts+++ b/apps/client/src/widgets/note_tree.ts@@ -1614,14 +1614,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {return;}- // Only navigate to parent if deleting the currently active note- const activeNoteId = appContext.tabManager.getActiveContext()?.noteId;- const isDeletingActiveNote = branchIds.some((branchId) => {- const branch = froca.getBranch(branchId);- return branch?.noteId === activeNoteId;- });-- await branchService.deleteNotes(branchIds, false, isDeletingActiveNote);+ await branchService.deleteNotes(branchIds);this.clearSelectedNodes();}