Skip to content

Build your personal knowledge base with Trilium Notes

some fixes in note moving

azivner4d95eb0762bc
diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js
index 8188377005..6554e89d79 100644
--- a/public/javascripts/note_tree.js
+++ b/public/javascripts/note_tree.js
@@ -344,17 +344,17 @@ const noteTree = (function() {
const beforeNode = node.getPrevSibling();
if (beforeNode !== null) {
- treeChanges.moveBeforeNode(node, beforeNode);
+ treeChanges.moveBeforeNode(node, beforeNode, false);
}
},
"shift+down": node => {
let afterNode = node.getNextSibling();
if (afterNode !== null) {
- treeChanges.moveAfterNode(node, afterNode);
+ treeChanges.moveAfterNode(node, afterNode, false);
}
},
"shift+left": node => {
- treeChanges.moveNodeUp(node);
+ treeChanges.moveNodeUpInHierarchy(node);
},
"shift+right": node => {
let toNode = node.getPrevSibling();
diff --git a/public/javascripts/tree_changes.js b/public/javascripts/tree_changes.js
index 4c94df2b09..df209aaff9 100644
--- a/public/javascripts/tree_changes.js
+++ b/public/javascripts/tree_changes.js
@@ -1,7 +1,7 @@
"use strict";
const treeChanges = (function() {
- async function moveBeforeNode(node, beforeNode) {
+ async function moveBeforeNode(node, beforeNode, changeInPath = true) {
await $.ajax({
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveBefore/' + beforeNode.data.note_tree_id,
type: 'PUT',
@@ -10,10 +10,14 @@ const treeChanges = (function() {
node.moveTo(beforeNode, 'before');
+ if (changeInPath) {
+ recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
+ }
+
noteTree.setCurrentNotePathToHash(node);
}
- async function moveAfterNode(node, afterNode) {
+ async function moveAfterNode(node, afterNode, changeInPath = true) {
await $.ajax({
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + afterNode.data.note_tree_id,
type: 'PUT',
@@ -22,6 +26,10 @@ const treeChanges = (function() {
node.moveTo(afterNode, 'after');
+ if (changeInPath) {
+ recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
+ }
+
noteTree.setCurrentNotePathToHash(node);
}
@@ -55,6 +63,8 @@ const treeChanges = (function() {
toNode.folder = true;
toNode.renderTitle();
+ recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
+
noteTree.setCurrentNotePathToHash(node);
}
@@ -88,7 +98,7 @@ const treeChanges = (function() {
node.getParent().renderTitle();
}
- recentNotes.removeRecentNote(node.note_tree_id);
+ recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
let next = node.getNextSibling();
if (!next) {
@@ -103,24 +113,25 @@ const treeChanges = (function() {
noteTree.setCurrentNotePathToHash(next);
}
- async function moveNodeUp(node) {
- if (node.getParent() !== null) {
- $.ajax({
- url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + node.getParent().data.note_tree_id,
- type: 'PUT',
- contentType: "application/json",
- success: () => {
- if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {
- node.getParent().folder = false;
- node.getParent().renderTitle();
- }
-
- node.moveTo(node.getParent(), 'after');
-
- noteTree.setCurrentNotePathToHash(node);
- }
- });
+ async function moveNodeUpInHierarchy(node) {
+ if (node.getParent() === null) {
+ return;
+ }
+
+ await $.ajax({
+ url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + node.getParent().data.note_tree_id,
+ type: 'PUT',
+ contentType: "application/json",
+ });
+
+ if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {
+ node.getParent().folder = false;
+ node.getParent().renderTitle();
}
+
+ node.moveTo(node.getParent(), 'after');
+
+ noteTree.setCurrentNotePathToHash(node);
}
return {
@@ -128,7 +139,7 @@ const treeChanges = (function() {
moveAfterNode,
moveToNode,
deleteNode,
- moveNodeUp,
+ moveNodeUpInHierarchy,
cloneNoteAfter,
cloneNoteTo
};