From ad48b598938c8886e17d847c860de2e8e7091e2e Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 5 Jun 2020 00:07:45 +0200 Subject: [PATCH] no need to reload whole subtree while moving notes --- src/public/app/widgets/note_tree.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 7fc87f2a9..4b1416d1f 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -970,7 +970,9 @@ export default class NoteTreeWidget extends TabAwareWidget { const found = (parentNode.getChildren() || []).find(child => child.data.noteId === branch.noteId); if (!found) { - noteIdsToReload.add(branch.parentNoteId); + parentNode.addChildren([await this.prepareNode(branch)]); + + this.sortChildren(parentNode); } } } @@ -992,16 +994,7 @@ export default class NoteTreeWidget extends TabAwareWidget { for (const parentNoteId of loadResults.getNoteReorderings()) { for (const node of this.getNodesByNoteId(parentNoteId)) { if (node.isLoaded()) { - node.sortChildren((nodeA, nodeB) => { - const branchA = treeCache.branches[nodeA.data.branchId]; - const branchB = treeCache.branches[nodeB.data.branchId]; - - if (!branchA || !branchB) { - return 0; - } - - return branchA.notePosition - branchB.notePosition; - }); + this.sortChildren(node); } } } @@ -1047,6 +1040,19 @@ export default class NoteTreeWidget extends TabAwareWidget { } } + sortChildren(node) { + node.sortChildren((nodeA, nodeB) => { + const branchA = treeCache.branches[nodeA.data.branchId]; + const branchB = treeCache.branches[nodeB.data.branchId]; + + if (!branchA || !branchB) { + return 0; + } + + return branchA.notePosition - branchB.notePosition; + }); + } + async setExpanded(branchId, isExpanded) { utils.assertArguments(branchId);