mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	simplification of internal structure/methods in note_tree
This commit is contained in:
		| @@ -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'; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user