Skip to content

Build your personal knowledge base with Trilium Notes

fix(tree): restore scroll to active note when switching workspaces

Elian Doran572a6125f3f9
diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.ts
index 4314ee4df7..1a6f7e6087 100644
--- a/apps/client/src/widgets/note_tree.ts
+++ b/apps/client/src/widgets/note_tree.ts
@@ -1543,8 +1543,9 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
}
const hoistedNotePath = await treeService.resolveNotePath(this.noteContext.hoistedNoteId);
+ const hoistChanged = this.lastFilteredHoistedNotePath !== hoistedNotePath;
- if (!forceUpdate && this.lastFilteredHoistedNotePath === hoistedNotePath) {
+ if (!forceUpdate && !hoistChanged) {
// Hoisting did not change, so skip the expensive re-filter (avoids flickering on
// simple note changes with large subtrees). The hidden-node class must still be
// reapplied — the <li> may have been recreated by a lazy reload (e.g. via
@@ -1578,6 +1579,16 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
this.setExpanded(node.data.branchId, true);
}
}
+
+ // Re-applying the filter (clearFilter / filterBranches) rebuilds the visible node set and
+ // resets the tree's scroll position to the top. When the hoisted note actually changed —
+ // e.g. switching between tabs belonging to different workspaces — bring the active note
+ // back into view so the tree doesn't jump to the top. We deliberately skip this when the
+ // hoist is unchanged (frequent forceUpdate re-filters during editing/sync) to avoid
+ // yanking the tree away from wherever the user scrolled.
+ if (hoistChanged) {
+ this.getActiveNode()?.makeVisible({ scrollIntoView: true });
+ }
}
toggleHiddenNode(show: boolean) {