From fba68681aae34c2ec066d8592e0b75a5d8b9bed7 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 9 Mar 2021 20:37:56 +0100 Subject: [PATCH] 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 --- src/public/app/services/hoisted_note.js | 6 ++---- src/public/app/services/tree.js | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.js index f7c97e103..efdc66e1c 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 ee4b5bb83..1d7f40fb0 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') {