diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index c17223b69..2f568e6c2 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -164,7 +164,19 @@ async function handleProtectedSession() { } async function loadNoteDetail(noteId) { - currentNote = await loadNote(noteId); + const loadedNote = await loadNote(noteId); + + // we will try to render the new note only if it's still the active one in the tree + // this is useful when user quickly switches notes (by e.g. holding down arrow) so that we don't + // try to render all those loaded notes one after each other. This only guarantees that correct note + // will be displayed independent of timing + const currentTreeNode = treeService.getCurrentNode(); + if (currentTreeNode && currentTreeNode.data.noteId !== loadedNote.noteId) { + return; + } + + currentNote = loadedNote; + refreshAttributes(); // needs to happend after loading the note itself because it references current noteId if (isNewNoteCreated) { diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index fe00f6d5b..3fd9be332 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -332,13 +332,14 @@ function initFancyTree(tree) { } }, activate: (event, data) => { - const node = data.node.data; + const node = data.node; + const noteId = node.data.noteId; - setCurrentNotePathToHash(data.node); + setCurrentNotePathToHash(node); - noteDetailService.switchToNote(node.noteId); + noteDetailService.switchToNote(noteId); - showPaths(node.noteId, data.node); + showPaths(noteId, node); }, expand: (event, data) => setExpandedToServer(data.node.data.branchId, true), collapse: (event, data) => setExpandedToServer(data.node.data.branchId, false),