From ca041bb658f54ef8e199f9f0d80525a996eebeb9 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 19 Oct 2023 08:58:04 +0200 Subject: [PATCH] fix expanded status when moving note trees --- src/public/app/widgets/note_tree.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index a586dfbde..20d064a80 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -1147,6 +1147,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { let parentsOfAddedNodes = []; const allBranchRows = loadResults.getBranchRows(); + // TODO: this flag is suspicious - why does it matter that all branches in a particular update are deleted? const allBranchesDeleted = allBranchRows.every(branchRow => !!branchRow.isDeleted); for (const branchRow of allBranchRows) { @@ -1159,8 +1160,8 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { noteIdsToUpdate.add(branchRow.noteId); } - for (const node of this.getNodesByBranch(branchRow)) { - if (branchRow.isDeleted) { + if (branchRow.isDeleted) { + for (const node of this.getNodesByBranch(branchRow)) { if (node.isActive()) { if (allBranchesDeleted) { const newActiveNode = node.getNextSibling() @@ -1181,9 +1182,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { noteIdsToUpdate.add(branchRow.parentNoteId); } - } - - if (!branchRow.isDeleted) { + } else { for (const parentNode of this.getNodesByNoteId(branchRow.parentNoteId)) { parentsOfAddedNodes.push(parentNode) @@ -1194,12 +1193,16 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { const found = (parentNode.getChildren() || []).find(child => child.data.noteId === branchRow.noteId); if (!found) { // make sure it's loaded - await froca.getNote(branchRow.noteId); + const note = await froca.getNote(branchRow.noteId); const frocaBranch = froca.getBranch(branchRow.branchId); // we're forcing lazy since it's not clear if the whole required subtree is in froca parentNode.addChildren([this.prepareNode(frocaBranch, true)]); + if (frocaBranch.isExpanded && note.hasChildren()) { + noteIdsToReload.add(frocaBranch.noteId); + } + this.sortChildren(parentNode); // this might be a first child which would force an icon change