recovery if note path changes, plus change of note path after note move

This commit is contained in:
azivner
2017-11-19 18:16:50 -05:00
parent 14787e0283
commit e992087720
4 changed files with 75 additions and 54 deletions

View File

@@ -139,15 +139,24 @@ const noteTree = (function() {
const effectivePath = [];
let childNoteId = null;
let i = 0;
while (true) {
const parentNoteId = i < path.length ? path[i] : null;
i++;
for (const parentNoteId of path) {
if (childNoteId !== null) {
const parents = childToParents[childNoteId];
if (!parents.includes(parentNoteId)) {
if (parentNoteId === null || !parents.includes(parentNoteId)) {
console.log("Did not find parent " + parentNoteId + " for child " + childNoteId);
if (parents.length > 0) {
if (parents[0] === 'root') {
console.log("Reached root.");
break;
}
childNoteId = parents[0];
effectivePath.push(childNoteId);
@@ -196,6 +205,14 @@ const noteTree = (function() {
});
}
function setCurrentNotePathToHash(node) {
const currentNotePath = treeUtils.getNotePath(node);
document.location.hash = currentNotePath;
recentNotes.addRecentNote(currentNotePath);
}
function initFancyTree(noteTree) {
const keybindings = {
"insert": node => {
@@ -246,11 +263,8 @@ const noteTree = (function() {
scrollParent: $("#tree"),
activate: (event, data) => {
const node = data.node.data;
const currentNotePath = treeUtils.getNotePath(data.node);
document.location.hash = currentNotePath;
recentNotes.addRecentNote(currentNotePath);
setCurrentNotePathToHash(data.node);
noteEditor.switchToNote(node.note_id);
},
@@ -471,6 +485,7 @@ const noteTree = (function() {
getCurrentNoteTreeId,
activateNode,
getCurrentNotePath,
getNoteTitle
getNoteTitle,
setCurrentNotePathToHash
};
})();