From 89a0c5a1c915b0570d5d5d3d8dea0ee1a9e696a7 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 28 Feb 2021 19:46:04 +0100 Subject: [PATCH] fix "no data" when switching between tabs with different hoisted notes, closes #1699 --- src/public/app/services/spaced_update.js | 2 +- src/public/app/widgets/note_tree.js | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/public/app/services/spaced_update.js b/src/public/app/services/spaced_update.js index bf61550b2..300edc13d 100644 --- a/src/public/app/services/spaced_update.js +++ b/src/public/app/services/spaced_update.js @@ -15,7 +15,7 @@ export default class SpacedUpdate { async updateNowIfNecessary() { if (this.changed) { - this.changed = false; // optimistic...k + this.changed = false; // optimistic... try { await this.updater(); diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 75e34d904..cd81698c5 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -804,12 +804,11 @@ export default class NoteTreeWidget extends TabAwareWidget { /** @return {FancytreeNode} */ async getNodeFromPath(notePath, expand = false, logErrors = true) { utils.assertArguments(notePath); + /** @let {FancytreeNode} */ + let parentNode = this.getNodesByNoteId('root')[0]; - const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); - /** @const {FancytreeNode} */ - let parentNode = null; - - const resolvedNotePathSegments = await treeService.resolveNotePathToSegments(notePath, logErrors); + const resolvedNotePathSegments = (await treeService.resolveNotePathToSegments(notePath, logErrors)) + .slice(1); if (!resolvedNotePathSegments) { if (logErrors) { @@ -820,13 +819,6 @@ export default class NoteTreeWidget extends TabAwareWidget { } for (const childNoteId of resolvedNotePathSegments) { - if (childNoteId === hoistedNoteId) { - // there must be exactly one node with given hoistedNoteId - parentNode = this.getNodesByNoteId(childNoteId)[0]; - - continue; - } - // we expand only after hoisted note since before then nodes are not actually present in the tree if (parentNode) { if (!parentNode.isLoaded()) { @@ -857,7 +849,7 @@ export default class NoteTreeWidget extends TabAwareWidget { // these are real notes with real notePath, user can display them in a detail // but they don't have a node in the tree - ws.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}, requested path is ${notePath}`); + ws.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteService.getHoistedNoteId()}, requested path is ${notePath}`); } return; @@ -1207,8 +1199,12 @@ export default class NoteTreeWidget extends TabAwareWidget { } } - filterHoistedBranch() { + async filterHoistedBranch() { if (this.tabContext) { + // make sure the hoisted node is loaded (can be unloaded e.g. after tree collapse in another tab) + const hoistedNotePath = await treeService.resolveNotePath(this.tabContext.hoistedNoteId); + await this.getNodeFromPath(hoistedNotePath); + if (this.tabContext.hoistedNoteId === 'root') { this.tree.clearFilter(); }