mirror of
https://github.com/zadam/trilium.git
synced 2025-02-24 23:13:43 +08:00
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
This commit is contained in:
parent
50c84e0f5f
commit
fba68681aa
2 changed files with 18 additions and 8 deletions
|
@ -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?")) {
|
||||
|
|
|
@ -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') {
|
||||
|
|
Loading…
Reference in a new issue