From 74b41c9911e32b4244aac6077de54ae6ff310fb2 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 1 Jun 2019 14:12:27 +0200 Subject: [PATCH] tree reloads should preserve activated node, fixes #552 --- src/public/javascripts/services/tree.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index 8f99862c2..0f98794f4 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -369,8 +369,6 @@ async function treeInitialized() { setFrontendAsLoaded(); } -let ignoreNextActivationNoteId = null; - function initFancyTree(tree) { utils.assertArguments(tree); @@ -402,16 +400,6 @@ function initFancyTree(tree) { return false; } }, - beforeActivate: (event, data) => { - // make sure the reload won't trigger reactivation. - // This is important especially in cases where we wait for the reload to finish to then activate some other note. - // But since the activate() event is called asynchronously, it may be called (or finished calling) - // after we switched to a different note so it's not possible to just check if current note matches requested note - if (ignoreNextActivationNoteId && getActiveNode() !== null && getActiveNode().data.noteId === data.node.data.noteId) { - ignoreNextActivationNoteId = null; - return false; - } - }, activate: async (event, data) => { // click event won't propagate so let's close context menu manually contextMenuWidget.hideContextMenu(); @@ -490,11 +478,16 @@ function getTree() { async function reload() { const notes = await loadTree(); - if (getActiveNode()) { - ignoreNextActivationNoteId = getActiveNode().data.noteId; - } + const activeNotePath = getActiveNode() !== null ? await treeUtils.getNotePath(getActiveNode()) : null; await getTree().reload(notes); + + // reactivate originally activated node, but don't trigger note loading + if (activeNotePath) { + const node = await getNodeFromPath(activeNotePath, true); + + await node.setActive(true, {noEvents: true}); + } } function isNotePathInAddress() {