fix activating note by noteId when hoisting, fixes #320

This commit is contained in:
azivner 2019-01-10 19:53:42 +01:00
parent 0722494d41
commit 48bbfb8bdb

View File

@ -94,32 +94,41 @@ async function expandToNote(notePath, expandOpts) {
const noteId = treeUtils.getNoteIdFromNotePath(notePath); const noteId = treeUtils.getNoteIdFromNotePath(notePath);
const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();
let hoistedNoteFound = false;
let parentNoteId = null; let parentNoteId = null;
for (const childNoteId of runPath) { for (const childNoteId of runPath) {
// for first node (!parentNoteId) it doesn't matter which node is found if (childNoteId === hoistedNoteId) {
let node = getNode(childNoteId, parentNoteId); hoistedNoteFound = true;
}
if (!node && parentNoteId) { // we expand only after hoisted note since before then nodes are not actually present in the tree
const parents = getNodesByNoteId(parentNoteId); if (hoistedNoteFound) {
// for first node (!parentNoteId) it doesn't matter which node is found
let node = getNode(childNoteId, parentNoteId);
for (const parent of parents) { if (!node && parentNoteId) {
// force load parents. This is useful when fancytree doesn't contain recently created notes yet. const parents = getNodesByNoteId(parentNoteId);
await parent.load(true);
for (const parent of parents) {
// force load parents. This is useful when fancytree doesn't contain recently created notes yet.
await parent.load(true);
}
node = getNode(childNoteId, parentNoteId);
} }
node = getNode(childNoteId, parentNoteId); if (!node) {
} console.error(`Can't find node for noteId=${childNoteId} with parentNoteId=${parentNoteId}`);
}
if (!node) { if (childNoteId === noteId) {
console.error(`Can't find node for noteId=${childNoteId} with parentNoteId=${parentNoteId}`); return node;
} } else {
await node.setExpanded(true, expandOpts);
if (childNoteId === noteId) { }
return node;
}
else {
await node.setExpanded(true, expandOpts);
} }
parentNoteId = childNoteId; parentNoteId = childNoteId;
@ -129,9 +138,12 @@ async function expandToNote(notePath, expandOpts) {
async function activateNote(notePath, noteLoadedListener) { async function activateNote(notePath, noteLoadedListener) {
utils.assertArguments(notePath); utils.assertArguments(notePath);
// notePath argument can contain only noteId which is not good when hoisted since
// then we need to check the whole note path
const runNotePath = await getRunPath(notePath);
const hoistedNoteId = await hoistedNoteService.getHoistedNoteId(); const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();
if (hoistedNoteId !== 'root' && !notePath.includes(hoistedNoteId)) { if (hoistedNoteId !== 'root' && !runNotePath.includes(hoistedNoteId)) {
if (!await confirmDialog.confirm("Requested note is outside of hoisted note subtree. Do you want to unhoist?")) { if (!await confirmDialog.confirm("Requested note is outside of hoisted note subtree. Do you want to unhoist?")) {
return; return;
} }