From b700f069fedc3c067155d3ad4339bef7baba1ad9 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 6 Nov 2023 23:11:57 +0100 Subject: [PATCH] reduce flickering while hoisted --- src/public/app/widgets/note_tree.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 70f29991a..ad0d41a87 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -833,7 +833,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { } }); - await this.filterHoistedBranch(); + await this.filterHoistedBranch(true); // don't activate the active note, see discussion in https://github.com/zadam/trilium/issues/3664 } @@ -1021,7 +1021,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { } } - this.filterHoistedBranch(); + this.filterHoistedBranch(false); } async refreshSearch(e) { @@ -1080,7 +1080,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { } }, false); - this.filterHoistedBranch(); + this.filterHoistedBranch(true); }, 600 * 1000); } @@ -1112,7 +1112,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { if (refreshCtx.noteIdsToReload.size > 0 || refreshCtx.noteIdsToUpdate.size > 0) { // workaround for https://github.com/mar10/fancytree/issues/1054 - this.filterHoistedBranch(); + this.filterHoistedBranch(true); } } @@ -1371,7 +1371,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { await this.tree.reload([rootNode]); }); - await this.filterHoistedBranch(); + await this.filterHoistedBranch(true); if (activeNotePath) { const node = await this.getNodeFromPath(activeNotePath, true); @@ -1384,16 +1384,25 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { async hoistedNoteChangedEvent({ntxId}) { if (this.isNoteContext(ntxId)) { - await this.filterHoistedBranch(); + await this.filterHoistedBranch(true); } } - async filterHoistedBranch() { + async filterHoistedBranch(forceUpdate = false) { if (!this.noteContext) { return; } const hoistedNotePath = await treeService.resolveNotePath(this.noteContext.hoistedNoteId); + + if (!forceUpdate && this.lastFilteredHoistedNotePath === hoistedNotePath) { + // no need to re-filter if the hoisting did not change + // (helps with flickering on simple note change with large subtrees) + return; + } + + this.lastFilteredHoistedNotePath = hoistedNotePath; + await this.getNodeFromPath(hoistedNotePath); if (this.noteContext.hoistedNoteId === 'root') {