better algorithm to find note if note path is invalid

This commit is contained in:
azivner 2017-11-30 00:02:32 -05:00
parent d0a0366b05
commit 7c7a5f19f5

View File

@ -191,8 +191,11 @@ const noteTree = (function() {
let i = 0; let i = 0;
while (true) { while (true) {
const parentNoteId = i < path.length ? path[i] : null; if (i >= path.length) {
i++; break;
}
const parentNoteId = path[i++];
if (childNoteId !== null) { if (childNoteId !== null) {
const parents = childToParents[childNoteId]; const parents = childToParents[childNoteId];
@ -202,20 +205,17 @@ const noteTree = (function() {
return; return;
} }
if (parentNoteId === null || !parents.includes(parentNoteId)) { if (!parents.includes(parentNoteId)) {
console.log("Did not find parent " + parentNoteId + " for child " + childNoteId); console.log("Did not find parent " + parentNoteId + " for child " + childNoteId);
if (parents.length > 0) { if (parents.length > 0) {
if (parents[0] === 'root') { const pathToRoot = getSomeNotePath(parents[0]).split("/").reverse();
console.log("Reached root.");
break; for (const noteId of pathToRoot) {
effectivePath.push(noteId);
} }
childNoteId = parents[0]; break;
effectivePath.push(childNoteId);
console.log("Choosing parent " + childNoteId + " instead.");
continue;
} }
else { else {
console.log("No parents, can't activate node."); console.log("No parents, can't activate node.");