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(client): activate tree nodes in popups hoisted into the hidden subtree
Elian Doranec3cb5a02972
diff --git a/apps/client/src/services/hoisted_note.spec.ts b/apps/client/src/services/hoisted_note.spec.tsindex 3c92708baa..39f749d669 100644--- a/apps/client/src/services/hoisted_note.spec.ts+++ b/apps/client/src/services/hoisted_note.spec.ts@@ -117,6 +117,19 @@ describe("hoisted_note service", () => {setActiveContext(orphan.noteId);expect(await hoistedNoteService.isHoistedInHiddenSubtree()).toBe(true);});++ it("honours an explicit hoistedNoteId over the active context (e.g. a tree popup)", async () => {+ buildNote({ id: "root", title: "Root" });+ const visible = buildNote({ title: "Visible" });+ visible.parents.push("root");+ const orphan = buildNote({ title: "Orphan" }); // hidden completely++ // Active tab hoisted on a visible note, but the caller (a popup tree) is hoisted into the+ // hidden subtree — the explicit argument must win.+ setActiveContext(visible.noteId);+ expect(await hoistedNoteService.isHoistedInHiddenSubtree(orphan.noteId)).toBe(true);+ expect(await hoistedNoteService.isHoistedInHiddenSubtree("root")).toBe(false);+ });});describe("checkNoteAccess", () => {diff --git a/apps/client/src/services/hoisted_note.ts b/apps/client/src/services/hoisted_note.tsindex f41f08e066..0b71440d06 100644--- a/apps/client/src/services/hoisted_note.ts+++ b/apps/client/src/services/hoisted_note.ts@@ -28,10 +28,13 @@ function isHoistedNode(node: Fancytree.FancytreeNode) {return node.data.noteId === "root" || node.data.noteId === getHoistedNoteId();}-async function isHoistedInHiddenSubtree() {- const hoistedNoteId = getHoistedNoteId();-- if (hoistedNoteId === "root") {+/**+ * Whether the given hoisted note lives entirely within the hidden subtree. Defaults to the active+ * tab's hoisted note, but callers bound to another context (e.g. a tree popup with its own hoist)+ * must pass that context's `hoistedNoteId` — otherwise the check reads the wrong context.+ */+async function isHoistedInHiddenSubtree(hoistedNoteId = getHoistedNoteId()) {+ if (!hoistedNoteId || hoistedNoteId === "root") {return false;}diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.tsindex 7b5fde0b92..9dbbaaaeab 100644--- a/apps/client/src/widgets/note_tree.ts+++ b/apps/client/src/widgets/note_tree.ts@@ -1158,7 +1158,9 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {const newActiveNode =this.noteContext?.notePath &&- (!treeService.isNotePathInHiddenSubtree(this.noteContext.notePath) || (await hoistedNoteService.isHoistedInHiddenSubtree())) &&+ // Pass this tree's own hoisted note (e.g. a popup hoisted into the hidden subtree) rather+ // than the active tab's — otherwise a hidden-subtree note never gets an active node here.+ (!treeService.isNotePathInHiddenSubtree(this.noteContext.notePath) || (await hoistedNoteService.isHoistedInHiddenSubtree(this.hoistedNoteId))) &&(await this.getNodeFromPath(this.noteContext.notePath));if (this.spotlightedNode && newActiveNode !== this.spotlightedNode) {