From 35d5289cca802192a7dba569e9afc23996e60cce Mon Sep 17 00:00:00 2001 From: azivner Date: Fri, 17 Nov 2017 22:52:24 -0500 Subject: [PATCH] jump to note works with lazy loaded note tree --- public/javascripts/tree_utils.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/public/javascripts/tree_utils.js b/public/javascripts/tree_utils.js index 7981f63ed..81a028801 100644 --- a/public/javascripts/tree_utils.js +++ b/public/javascripts/tree_utils.js @@ -15,10 +15,31 @@ const treeUtils = (function() { return treeEl.fancytree('getNodeByKey', noteId); } - function activateNode(noteId) { - const node = treeUtils.getNodeByKey(noteId); + async function activateNode(noteIdToActivate) { + const noteIdPath = [ noteIdToActivate ]; - node.setActive(); + let note = noteTree.getByNoteId(noteIdToActivate); + + while (note) { + if (note.note_pid !== 'root') { + noteIdPath.push(note.note_pid); + } + + note = noteTree.getByNoteId(note.note_pid); + } + + for (const noteId of noteIdPath.reverse()) { + console.log("Activating/expanding " + noteId); + + const node = treeUtils.getNodeByKey(noteId); + + if (noteId !== noteIdToActivate) { + await node.setExpanded(); + } + else { + await node.setActive(); + } + } } function getNoteTitle(noteId) {