mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
simplification of internal structure/methods in note_tree
This commit is contained in:
parent
acba72ec4c
commit
0ec6d4baa8
@ -8,7 +8,7 @@ const contextMenu = (function() {
|
|||||||
|
|
||||||
function pasteAfter(node) {
|
function pasteAfter(node) {
|
||||||
if (clipboardMode === 'cut') {
|
if (clipboardMode === 'cut') {
|
||||||
const subjectNode = treeUtils.getNodeByNoteTreeId(clipboardId);
|
const subjectNode = treeUtils.getNodeByKey(clipboardId);
|
||||||
|
|
||||||
treeChanges.moveAfterNode(subjectNode, node);
|
treeChanges.moveAfterNode(subjectNode, node);
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ const contextMenu = (function() {
|
|||||||
|
|
||||||
function pasteInto(node) {
|
function pasteInto(node) {
|
||||||
if (clipboardMode === 'cut') {
|
if (clipboardMode === 'cut') {
|
||||||
const subjectNode = treeUtils.getNodeByNoteTreeId(clipboardId);
|
const subjectNode = treeUtils.getNodeByKey(clipboardId);
|
||||||
|
|
||||||
treeChanges.moveToNode(subjectNode, node);
|
treeChanges.moveToNode(subjectNode, node);
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ const contextMenu = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cut(node) {
|
function cut(node) {
|
||||||
clipboardId = node.data.note_tree_id;
|
clipboardId = node.key;
|
||||||
clipboardMode = 'cut';
|
clipboardMode = 'cut';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,10 @@ const noteTree = (function() {
|
|||||||
let startNoteTreeId = null;
|
let startNoteTreeId = null;
|
||||||
let treeLoadTime = null;
|
let treeLoadTime = null;
|
||||||
let notesMap = {};
|
let notesMap = {};
|
||||||
|
|
||||||
let parentToChildren = {};
|
let parentToChildren = {};
|
||||||
let childToParents = {};
|
let childToParents = {};
|
||||||
let counter = 1;
|
|
||||||
let noteTreeIdToKey = {};
|
|
||||||
let parentChildToNoteTreeId = {};
|
let parentChildToNoteTreeId = {};
|
||||||
let noteIdToTitle = {};
|
let noteIdToTitle = {};
|
||||||
|
|
||||||
@ -21,10 +21,6 @@ const noteTree = (function() {
|
|||||||
return node.note_tree_id;
|
return node.note_tree_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getKeyFromNoteTreeId(noteTreeId) {
|
|
||||||
return noteTreeIdToKey[noteTreeId];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTreeLoadTime() {
|
function getTreeLoadTime() {
|
||||||
return treeLoadTime;
|
return treeLoadTime;
|
||||||
}
|
}
|
||||||
@ -120,12 +116,9 @@ const noteTree = (function() {
|
|||||||
node.extraClasses = node.extraClasses.substr(1);
|
node.extraClasses = node.extraClasses.substr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
node.key = counter++ + ""; // key needs to be string
|
|
||||||
node.refKey = note.note_id;
|
node.refKey = note.note_id;
|
||||||
node.expanded = note.is_expanded;
|
node.expanded = note.is_expanded;
|
||||||
|
|
||||||
noteTreeIdToKey[noteTreeId] = node.key;
|
|
||||||
|
|
||||||
if (parentToChildren[note.note_id] && parentToChildren[note.note_id].length > 0) {
|
if (parentToChildren[note.note_id] && parentToChildren[note.note_id].length > 0) {
|
||||||
node.folder = true;
|
node.folder = true;
|
||||||
|
|
||||||
@ -189,9 +182,7 @@ const noteTree = (function() {
|
|||||||
let parentNoteId = 'root';
|
let parentNoteId = 'root';
|
||||||
|
|
||||||
for (const childNoteId of runPath) {
|
for (const childNoteId of runPath) {
|
||||||
const noteTreeId = getNoteTreeId(parentNoteId, childNoteId);
|
const node = getNodes(childNoteId).find(node => node.data.note_pid === parentNoteId);
|
||||||
|
|
||||||
const node = treeUtils.getNodeByNoteTreeId(noteTreeId);
|
|
||||||
|
|
||||||
if (childNoteId === noteId) {
|
if (childNoteId === noteId) {
|
||||||
await node.setActive();
|
await node.setActive();
|
||||||
@ -204,6 +195,10 @@ const noteTree = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getNodes(noteId) {
|
||||||
|
return getTree().getNodesByRef(noteId);
|
||||||
|
}
|
||||||
|
|
||||||
function showParentList(noteId, node) {
|
function showParentList(noteId, node) {
|
||||||
const parents = childToParents[noteId];
|
const parents = childToParents[noteId];
|
||||||
|
|
||||||
@ -467,7 +462,7 @@ const noteTree = (function() {
|
|||||||
$(document).bind('keydown', 'alt+c', collapseTree);
|
$(document).bind('keydown', 'alt+c', collapseTree);
|
||||||
|
|
||||||
function scrollToCurrentNote() {
|
function scrollToCurrentNote() {
|
||||||
const node = treeUtils.getNodeByNoteTreeId(noteEditor.getCurrentNoteId());
|
const node = noteTree.getCurrentNode();
|
||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
node.makeVisible({scrollIntoView: true});
|
node.makeVisible({scrollIntoView: true});
|
||||||
@ -568,7 +563,7 @@ const noteTree = (function() {
|
|||||||
const noteId = getCurrentNoteId();
|
const noteId = getCurrentNoteId();
|
||||||
|
|
||||||
if (noteId) {
|
if (noteId) {
|
||||||
return getTree().getNodesByRef(noteId);
|
return getNodes(noteId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return [];
|
return [];
|
||||||
@ -683,7 +678,6 @@ const noteTree = (function() {
|
|||||||
collapseTree,
|
collapseTree,
|
||||||
scrollToCurrentNote,
|
scrollToCurrentNote,
|
||||||
toggleSearch,
|
toggleSearch,
|
||||||
getKeyFromNoteTreeId,
|
|
||||||
getNoteTreeIdFromKey,
|
getNoteTreeIdFromKey,
|
||||||
setCurrentNoteTreeBasedOnProtectedStatus,
|
setCurrentNoteTreeBasedOnProtectedStatus,
|
||||||
getCurrentNode,
|
getCurrentNode,
|
||||||
|
@ -11,12 +11,6 @@ const treeUtils = (function() {
|
|||||||
return treeEl.fancytree('getNodeByKey', key);
|
return treeEl.fancytree('getNodeByKey', key);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNodeByNoteTreeId(noteTreeId) {
|
|
||||||
const key = noteTree.getKeyFromNoteTreeId(noteTreeId);
|
|
||||||
|
|
||||||
return getNodeByKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNoteIdFromNotePath(notePath) {
|
function getNoteIdFromNotePath(notePath) {
|
||||||
const path = notePath.split("/");
|
const path = notePath.split("/");
|
||||||
|
|
||||||
@ -47,7 +41,6 @@ const treeUtils = (function() {
|
|||||||
return {
|
return {
|
||||||
getParentProtectedStatus,
|
getParentProtectedStatus,
|
||||||
getNodeByKey,
|
getNodeByKey,
|
||||||
getNodeByNoteTreeId,
|
|
||||||
getFullNameForPath,
|
getFullNameForPath,
|
||||||
getNotePath,
|
getNotePath,
|
||||||
getNoteIdFromNotePath
|
getNoteIdFromNotePath
|
||||||
|
Loading…
x
Reference in New Issue
Block a user