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
refactor: 💡 Fix ts error
Jinb18cfb5d20a5
diff --git a/src/public/app/services/utils.ts b/src/public/app/services/utils.tsindex 53fd85a7b8..ee76093bbe 100644--- a/src/public/app/services/utils.ts+++ b/src/public/app/services/utils.ts@@ -411,7 +411,11 @@ async function openInAppHelp($button: JQuery<HTMLElement>) {if (inAppHelpPage) {// Dynamic import to avoid import issues in tests.const appContext = (await import("../components/app_context.js")).default;- const subContexts = appContext.tabManager.getActiveContext().getSubContexts();+ const activeContext = appContext.tabManager.getActiveContext();+ if (!activeContext) {+ return;+ }+ const subContexts = activeContext.getSubContexts();const targetNote = `_help_${inAppHelpPage}`;const helpSubcontext = subContexts.find((s) => s.viewScope?.viewMode === "contextual-help");const viewScope: ViewScope = {diff --git a/src/public/app/widgets/dialogs/recent_changes.ts b/src/public/app/widgets/dialogs/recent_changes.tsindex 9961817b1f..dbaca5268b 100644--- a/src/public/app/widgets/dialogs/recent_changes.ts+++ b/src/public/app/widgets/dialogs/recent_changes.ts@@ -115,7 +115,10 @@ export default class RecentChangesDialog extends BasicWidget {await ws.waitForMaxKnownEntityChangeId();- appContext.tabManager.getActiveContext().setNote(change.noteId);+ const activeContext = appContext.tabManager.getActiveContext();+ if (activeContext) {+ activeContext.setNote(change.noteId);+ }}});@@ -141,7 +144,10 @@ export default class RecentChangesDialog extends BasicWidget {// Skip clicks on the link or deleted notesif (e.target?.nodeName !== "A" && !change.current_isDeleted) {// Open the current note- appContext.tabManager.getActiveContext().setNote(change.noteId);+ const activeContext = appContext.tabManager.getActiveContext();+ if (activeContext) {+ activeContext.setNote(change.noteId);+ }}}).toggleClass("deleted-note", !!change.current_isDeleted)diff --git a/src/public/app/widgets/quick_search.ts b/src/public/app/widgets/quick_search.tsindex 90ed9325e1..f38d5e742c 100644--- a/src/public/app/widgets/quick_search.ts+++ b/src/public/app/widgets/quick_search.ts@@ -140,13 +140,19 @@ export default class QuickSearchWidget extends BasicWidget {if (!e.target || e.target.nodeName !== "A") {// click on the link is handled by link handling, but we want the whole item clickable- appContext.tabManager.getActiveContext().setNote(note.noteId);+ const activeContext = appContext.tabManager.getActiveContext();+ if (activeContext) {+ activeContext.setNote(note.noteId);+ }}});shortcutService.bindElShortcut($link, "return", () => {this.dropdown.hide();- appContext.tabManager.getActiveContext().setNote(note.noteId);+ const activeContext = appContext.tabManager.getActiveContext();+ if (activeContext) {+ activeContext.setNote(note.noteId);+ }});this.$dropdownMenu.append($link);diff --git a/src/public/app/widgets/tab_row.ts b/src/public/app/widgets/tab_row.tsindex 68557df3af..0f60a9c2e3 100644--- a/src/public/app/widgets/tab_row.ts+++ b/src/public/app/widgets/tab_row.ts@@ -419,13 +419,13 @@ export default class TabRowWidget extends BasicWidget {closeActiveTabCommand({ $el }: CommandListenerData<"closeActiveTab">) {const ntxId = $el.closest(".note-tab").attr("data-ntx-id");- appContext.tabManager.removeNoteContext(ntxId);+ appContext.tabManager.removeNoteContext(ntxId ?? null);}setTabCloseEvent($tab: JQuery<HTMLElement>) {$tab.on("mousedown", (e) => {if (e.which === 2) {- appContext.tabManager.removeNoteContext($tab.attr("data-ntx-id"));+ appContext.tabManager.removeNoteContext($tab.attr("data-ntx-id") ?? null);return true; // event has been handled}diff --git a/src/public/app/widgets/type_widgets/empty.ts b/src/public/app/widgets/type_widgets/empty.tsindex 8338f53ae0..e2a79e0c46 100644--- a/src/public/app/widgets/type_widgets/empty.ts+++ b/src/public/app/widgets/type_widgets/empty.ts@@ -87,7 +87,10 @@ export default class EmptyTypeWidget extends TypeWidget {return false;}- appContext.tabManager.getActiveContext().setNote(suggestion.notePath);+ const activeContext = appContext.tabManager.getActiveContext();+ if (activeContext) {+ activeContext.setNote(suggestion.notePath);+ }});this.$workspaceNotes = this.$widget.find(".workspace-notes");