Skip to content

Build your personal knowledge base with Trilium Notes

fix(split): only trigger focusOnDetail when necessary

SiriusXT407cac588a3e
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index bda3536da8..c44ca01aa7 100644
--- a/apps/client/src/components/app_context.ts
+++ b/apps/client/src/components/app_context.ts
@@ -487,7 +487,7 @@ type EventMappings = {
relationMapResetPanZoom: { ntxId: string | null | undefined };
relationMapResetZoomIn: { ntxId: string | null | undefined };
relationMapResetZoomOut: { ntxId: string | null | undefined };
- activeNoteChanged: {};
+ activeNoteChanged: {ntxId: string | null | undefined};
showAddLinkDialog: AddLinkOpts;
showIncludeDialog: IncludeNoteOpts;
openBulkActionsDialog: {
diff --git a/apps/client/src/components/tab_manager.ts b/apps/client/src/components/tab_manager.ts
index 127ec30b7d..3cf06a7793 100644
--- a/apps/client/src/components/tab_manager.ts
+++ b/apps/client/src/components/tab_manager.ts
@@ -165,7 +165,7 @@ export default class TabManager extends Component {
const activeNoteContext = this.getActiveContext();
this.updateDocumentTitle(activeNoteContext);
- this.triggerEvent("activeNoteChanged", {}); // trigger this even in on popstate event
+ this.triggerEvent("activeNoteChanged", {ntxId:activeNoteContext?.ntxId}); // trigger this even in on popstate event
}
calculateHash(): string {
diff --git a/apps/client/src/widgets/NoteDetail.tsx b/apps/client/src/widgets/NoteDetail.tsx
index 5b5838584c..1ee5c58c60 100644
--- a/apps/client/src/widgets/NoteDetail.tsx
+++ b/apps/client/src/widgets/NoteDetail.tsx
@@ -95,9 +95,11 @@ export default function NoteDetail() {
});
// Automatically focus the editor.
- useTriliumEvent("activeNoteChanged", () => {
- // Restore focus to the editor when switching tabs, but only if the note tree is not already focused.
- if (!document.activeElement?.classList.contains("fancytree-title")) {
+ useTriliumEvent("activeNoteChanged", ({ ntxId: eventNtxId }) => {
+ if (eventNtxId != ntxId) return;
+ // Restore focus to the editor when switching tabs,
+ // but only if the note tree and the note panel (e.g., note title or note detail) are not focused.
+ if (!document.activeElement?.classList.contains("fancytree-title") && !parentComponent.$widget[0].closest(".note-split")?.contains(document.activeElement)) {
parentComponent.triggerCommand("focusOnDetail", { ntxId });
}
});