Skip to content

Build your personal knowledge base with Trilium Notes

simplification of internal structure/methods in note_tree

azivner0ec6d4baa86b
diff --git a/public/javascripts/context_menu.js b/public/javascripts/context_menu.js
index 18d596c3d0..19fee4fc50 100644
--- a/public/javascripts/context_menu.js
+++ b/public/javascripts/context_menu.js
@@ -8,7 +8,7 @@ const contextMenu = (function() {
function pasteAfter(node) {
if (clipboardMode === 'cut') {
- const subjectNode = treeUtils.getNodeByNoteTreeId(clipboardId);
+ const subjectNode = treeUtils.getNodeByKey(clipboardId);
treeChanges.moveAfterNode(subjectNode, node);
}
@@ -25,7 +25,7 @@ const contextMenu = (function() {
function pasteInto(node) {
if (clipboardMode === 'cut') {
- const subjectNode = treeUtils.getNodeByNoteTreeId(clipboardId);
+ const subjectNode = treeUtils.getNodeByKey(clipboardId);
treeChanges.moveToNode(subjectNode, node);
}
@@ -46,7 +46,7 @@ const contextMenu = (function() {
}
function cut(node) {
- clipboardId = node.data.note_tree_id;
+ clipboardId = node.key;
clipboardMode = 'cut';
}
diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js
index f27730bafc..3c071eba7a 100644
--- a/public/javascripts/note_tree.js
+++ b/public/javascripts/note_tree.js
@@ -8,10 +8,10 @@ const noteTree = (function() {
let startNoteTreeId = null;
let treeLoadTime = null;
let notesMap = {};
+
let parentToChildren = {};
let childToParents = {};
- let counter = 1;
- let noteTreeIdToKey = {};
+
let parentChildToNoteTreeId = {};
let noteIdToTitle = {};
@@ -21,10 +21,6 @@ const noteTree = (function() {
return node.note_tree_id;
}
- function getKeyFromNoteTreeId(noteTreeId) {
- return noteTreeIdToKey[noteTreeId];
- }
-
function getTreeLoadTime() {
return treeLoadTime;
}
@@ -120,12 +116,9 @@ const noteTree = (function() {
node.extraClasses = node.extraClasses.substr(1);
}
- node.key = counter++ + ""; // key needs to be string
node.refKey = note.note_id;
node.expanded = note.is_expanded;
- noteTreeIdToKey[noteTreeId] = node.key;
-
if (parentToChildren[note.note_id] && parentToChildren[note.note_id].length > 0) {
node.folder = true;
@@ -189,9 +182,7 @@ const noteTree = (function() {
let parentNoteId = 'root';
for (const childNoteId of runPath) {
- const noteTreeId = getNoteTreeId(parentNoteId, childNoteId);
-
- const node = treeUtils.getNodeByNoteTreeId(noteTreeId);
+ const node = getNodes(childNoteId).find(node => node.data.note_pid === parentNoteId);
if (childNoteId === noteId) {
await node.setActive();
@@ -204,6 +195,10 @@ const noteTree = (function() {
}
}
+ function getNodes(noteId) {
+ return getTree().getNodesByRef(noteId);
+ }
+
function showParentList(noteId, node) {
const parents = childToParents[noteId];
@@ -467,7 +462,7 @@ const noteTree = (function() {
$(document).bind('keydown', 'alt+c', collapseTree);
function scrollToCurrentNote() {
- const node = treeUtils.getNodeByNoteTreeId(noteEditor.getCurrentNoteId());
+ const node = noteTree.getCurrentNode();
if (node) {
node.makeVisible({scrollIntoView: true});
@@ -568,7 +563,7 @@ const noteTree = (function() {
const noteId = getCurrentNoteId();
if (noteId) {
- return getTree().getNodesByRef(noteId);
+ return getNodes(noteId);
}
else {
return [];
@@ -683,7 +678,6 @@ const noteTree = (function() {
collapseTree,
scrollToCurrentNote,
toggleSearch,
- getKeyFromNoteTreeId,
getNoteTreeIdFromKey,
setCurrentNoteTreeBasedOnProtectedStatus,
getCurrentNode,
diff --git a/public/javascripts/tree_utils.js b/public/javascripts/tree_utils.js
index 144e0b260f..d580f89753 100644
--- a/public/javascripts/tree_utils.js
+++ b/public/javascripts/tree_utils.js
@@ -11,12 +11,6 @@ const treeUtils = (function() {
return treeEl.fancytree('getNodeByKey', key);
}
- function getNodeByNoteTreeId(noteTreeId) {
- const key = noteTree.getKeyFromNoteTreeId(noteTreeId);
-
- return getNodeByKey(key);
- }
-
function getNoteIdFromNotePath(notePath) {
const path = notePath.split("/");
@@ -47,7 +41,6 @@ const treeUtils = (function() {
return {
getParentProtectedStatus,
getNodeByKey,
- getNodeByNoteTreeId,
getFullNameForPath,
getNotePath,
getNoteIdFromNotePath