diff --git a/src/public/app/services/utils.ts b/src/public/app/services/utils.ts index 53fd85a7b..ee76093bb 100644 --- a/src/public/app/services/utils.ts +++ b/src/public/app/services/utils.ts @@ -411,7 +411,11 @@ async function openInAppHelp($button: JQuery) { 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.ts index 9961817b1..dbaca5268 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 notes if (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.ts index 90ed9325e..f38d5e742 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.ts index 68557df3a..0f60a9c2e 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) { $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.ts index 8338f53ae..e2a79e0c4 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");