Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(markdown): ToC lost when clicking on the same note
Elian Doran5c8912686489
diff --git a/apps/client/src/components/note_context.ts b/apps/client/src/components/note_context.tsindex a215491eee..f2504a73f8 100644--- a/apps/client/src/components/note_context.ts+++ b/apps/client/src/components/note_context.ts@@ -137,24 +137,30 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded">closeActiveDialog();}+ const previousNoteId = this.noteId;+this.notePath = resolvedNotePath;this.viewScope = opts.viewScope;({ noteId: this.noteId, parentNoteId: this.parentNoteId } = treeService.getNoteIdAndParentIdFromUrl(resolvedNotePath));- // Clear context data when switching notes and notify subscribers- const oldKeys = Array.from(this.contextData.keys());- this.contextData.clear();- if (oldKeys.length > 0) {- // Notify subscribers asynchronously to avoid blocking navigation- window.setTimeout(() => {- for (const key of oldKeys) {- this.triggerEvent("contextDataChanged", {- noteContext: this,- key,- value: undefined- });- }- }, 0);+ // Clear context data only when actually switching to a different note.+ // Context data (e.g. ToC headings) is tied to the note content, so it+ // remains valid when only the viewScope changes for the same note.+ if (this.noteId !== previousNoteId) {+ const oldKeys = Array.from(this.contextData.keys());+ this.contextData.clear();+ if (oldKeys.length > 0) {+ // Notify subscribers asynchronously to avoid blocking navigation+ window.setTimeout(() => {+ for (const key of oldKeys) {+ this.triggerEvent("contextDataChanged", {+ noteContext: this,+ key,+ value: undefined+ });+ }+ }, 0);+ }}this.saveToRecentNotes(resolvedNotePath);