mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-04-29 00:39:17 -05:00
recovery if note path changes, plus change of note path after note move
This commit is contained in:
@@ -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
|
||||
};
|
||||
})();
|
||||
@@ -3,29 +3,33 @@
|
||||
const treeChanges = (function() {
|
||||
function moveBeforeNode(node, beforeNode) {
|
||||
$.ajax({
|
||||
url: baseApiUrl + 'notes/' + node.key + '/moveBefore/' + beforeNode.key,
|
||||
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveBefore/' + beforeNode.data.note_tree_id,
|
||||
type: 'PUT',
|
||||
contentType: "application/json",
|
||||
success: () => {
|
||||
node.moveTo(beforeNode, 'before');
|
||||
|
||||
noteTree.setCurrentNotePathToHash(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function moveAfterNode(node, afterNode) {
|
||||
$.ajax({
|
||||
url: baseApiUrl + 'notes/' + node.key + '/moveAfter/' + afterNode.key,
|
||||
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + afterNode.data.note_tree_id,
|
||||
type: 'PUT',
|
||||
contentType: "application/json",
|
||||
success: () => {
|
||||
node.moveTo(afterNode, 'after');
|
||||
|
||||
noteTree.setCurrentNotePathToHash(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function moveToNode(node, toNode) {
|
||||
$.ajax({
|
||||
url: baseApiUrl + 'notes/' + node.key + '/moveTo/' + toNode.key,
|
||||
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveTo/' + toNode.data.note_id,
|
||||
type: 'PUT',
|
||||
contentType: "application/json",
|
||||
success: () => {
|
||||
@@ -35,6 +39,8 @@ const treeChanges = (function() {
|
||||
|
||||
toNode.folder = true;
|
||||
toNode.renderTitle();
|
||||
|
||||
noteTree.setCurrentNotePathToHash(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -63,6 +69,8 @@ const treeChanges = (function() {
|
||||
|
||||
// activate next element after this one is deleted so we don't lose focus
|
||||
next.setActive();
|
||||
|
||||
noteTree.setCurrentNotePathToHash(next);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,7 +79,7 @@ const treeChanges = (function() {
|
||||
function moveNodeUp(node) {
|
||||
if (node.getParent() !== null) {
|
||||
$.ajax({
|
||||
url: baseApiUrl + 'notes/' + node.key + '/moveAfter/' + node.getParent().key,
|
||||
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + node.getParent().data.note_tree_id,
|
||||
type: 'PUT',
|
||||
contentType: "application/json",
|
||||
success: () => {
|
||||
@@ -81,6 +89,8 @@ const treeChanges = (function() {
|
||||
}
|
||||
|
||||
node.moveTo(node.getParent(), 'after');
|
||||
|
||||
noteTree.setCurrentNotePathToHash(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user