Skip to content

Build your personal knowledge base with Trilium Notes

when resolving note path check if there's a hoisted note in it, if not, try again to find some path with hoisted note, closes #1718

zadamfba68681aae3
diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.js
index f7c97e1030..efdc66e1c7 100644
--- a/src/public/app/services/hoisted_note.js
+++ b/src/public/app/services/hoisted_note.js
@@ -26,9 +26,7 @@ function isHoistedNode(node) {
}
async function checkNoteAccess(notePath, tabContext) {
- // notePath argument can contain only noteId which is not good when hoisted since
- // then we need to check the whole note path
- const resolvedNotePath = await treeService.resolveNotePath(notePath);
+ const resolvedNotePath = await treeService.resolveNotePath(notePath, tabContext.hoistedNoteId);
if (!resolvedNotePath) {
console.log("Cannot activate " + notePath);
@@ -37,7 +35,7 @@ async function checkNoteAccess(notePath, tabContext) {
const hoistedNoteId = tabContext.hoistedNoteId;
- if (hoistedNoteId !== 'root' && !resolvedNotePath.includes(hoistedNoteId)) {
+ if (!resolvedNotePath.includes(hoistedNoteId)) {
const confirmDialog = await import('../dialogs/confirm.js');
if (!await confirmDialog.confirm("Requested note is outside of hoisted note subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?")) {
diff --git a/src/public/app/services/tree.js b/src/public/app/services/tree.js
index ee4b5bb83f..1d7f40fb0c 100644
--- a/src/public/app/services/tree.js
+++ b/src/public/app/services/tree.js
@@ -37,7 +37,7 @@ async function resolveNotePathToSegments(notePath, hoistedNoteId = 'root', logEr
path.push('root');
}
- const effectivePath = [];
+ const effectivePathSegments = [];
let childNoteId = null;
let i = 0;
@@ -81,7 +81,7 @@ async function resolveNotePathToSegments(notePath, hoistedNoteId = 'root', logEr
const pathToRoot = someNotePath.split("/").reverse().slice(1);
for (const noteId of pathToRoot) {
- effectivePath.push(noteId);
+ effectivePathSegments.push(noteId);
}
}
@@ -89,11 +89,23 @@ async function resolveNotePathToSegments(notePath, hoistedNoteId = 'root', logEr
}
}
- effectivePath.push(parentNoteId);
+ effectivePathSegments.push(parentNoteId);
childNoteId = parentNoteId;
}
- return effectivePath.reverse();
+ effectivePathSegments.reverse();
+
+ if (effectivePathSegments.includes(hoistedNoteId)) {
+ return effectivePathSegments;
+ }
+ else {
+ const note = await treeCache.getNote(getNoteIdFromNotePath(notePath));
+
+ const someNotePathSegments = getSomeNotePathSegments(note, hoistedNoteId);
+
+ // if there isn't actually any note path with hoisted note then return the original resolved note path
+ return someNotePathSegments.includes(hoistedNoteId) ? someNotePathSegments : effectivePathSegments;
+ }
}
function getSomeNotePathSegments(note, hoistedNotePath = 'root') {