Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager: fix an issue

Adorian Dorand85fef591d36
diff --git a/apps/client/src/services/content_manager.ts b/apps/client/src/services/content_manager.ts
index 94652c14da..929bb82ecf 100644
--- a/apps/client/src/services/content_manager.ts
+++ b/apps/client/src/services/content_manager.ts
@@ -369,9 +369,15 @@ function toArray(value: string | string[]) {
* renders the location under each title from the note's "best" path, so resolving that same path
* here makes the delete act on the placement the user can actually see, rather than on whichever
* branch happens to come first in cache order.
+ *
+ * @param activeNotePath tie-breaker for equally good paths, matching what the link resolution passes.
*/
-export function getDisplayedBranchId(note: FNote, hoistedNoteId = "root", activeNotePath: string | null = null) {
- const parentNoteId = note.getBestNotePath(hoistedNoteId, activeNotePath)?.at(-2);
+export function getDisplayedBranchId(note: FNote, activeNotePath: string | null = null) {
+ // Resolved from the root, never from the active hoist, because that is what `link.createLink`
+ // does when it renders the path — it calls `resolveNotePathToSegments(notePath)` without a
+ // hoisted note. Passing the active hoist here would pick a different placement for a note cloned
+ // both inside and outside the hoisted subtree, and delete something other than the row shows.
+ const parentNoteId = note.getBestNotePath("root", activeNotePath)?.at(-2);
const branchId = parentNoteId ? note.parentToBranch[parentNoteId] : undefined;
// Search results are backed by virtual branches, which cannot be deleted.
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.tsx b/apps/client/src/widgets/type_widgets/options/content_manager.tsx
index 198053c8e7..87aa119193 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager.tsx
@@ -57,11 +57,7 @@ function ContentItemMenu({ note }: { note: FNote }) {
hoistedNoteId: appContext.tabManager.getActiveContext()?.hoistedNoteId ?? null
});
} else if (command === "deleteNote") {
- const branchId = getDisplayedBranchId(
- note,
- appContext.tabManager.getActiveContext()?.hoistedNoteId ?? "root",
- appContext.tabManager.getActiveContextNotePath()
- );
+ const branchId = getDisplayedBranchId(note, appContext.tabManager.getActiveContextNotePath());
if (branchId) {
// One branch, not all of them: the dialog counts a note's *other* placements