From 77a014109e7e8ec3ee61890371da6b043dd9cee6 Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Thu, 30 Oct 2025 19:58:02 +0100 Subject: [PATCH] fix(note_autocomplete): fix attributes not linking --- apps/client/src/services/note_autocomplete.ts | 91 +++++++++++++------ .../ribbon/components/AttributeEditor.tsx | 12 +-- 2 files changed, 70 insertions(+), 33 deletions(-) diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.ts index f5141e061..f3de152a3 100644 --- a/apps/client/src/services/note_autocomplete.ts +++ b/apps/client/src/services/note_autocomplete.ts @@ -463,67 +463,105 @@ function initNoteAutocomplete($el: JQuery, options?: Options) { // TODO: Types fail due to "autocomplete:selected" not being registered in type definitions. ($el as any).on("autocomplete:selected", async (event: Event, suggestion: Suggestion) => { + $el.setSelectedNotePath(suggestion.notePath); + $el.setSelectedExternalLink(null); + $el.autocomplete("val", suggestion.noteTitle); + switch (suggestion.action) { case SuggestionAction.Command: { - $el.autocomplete("close"); - $el.trigger("autocomplete:commandselected", [suggestion]); break; } case SuggestionAction.ExternalLink: { - $el.setSelectedNotePath(null); - $el.setSelectedExternalLink(suggestion.externalLink); - $el.autocomplete("val", suggestion.externalLink); - $el.autocomplete("close"); - $el.trigger("autocomplete:externallinkselected", [suggestion]); break; } - case SuggestionAction.CreateNoteIntoInbox: - case SuggestionAction.CreateAndLinkNoteIntoInbox: { + // --- CREATE NOTE INTO INBOX --- + case SuggestionAction.CreateNoteIntoInbox: { const { note } = await noteCreateService.createNote( { target: "inbox", title: suggestion.noteTitle, activate: true, promptForType: true, - } as CreateNoteIntoInboxOpts + } ); - if (!note) return; + if (!note) + break; + + const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId; + suggestion.notePath = note?.getBestNotePathString(hoistedNoteId); + break; + } + + case SuggestionAction.CreateAndLinkNoteIntoInbox: { + const { note } = await noteCreateService.createNote( + { + target: "inbox", + title: suggestion.noteTitle, + activate: false, + promptForType: true, + } + ); + + if (!note) + break; const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId; suggestion.notePath = note?.getBestNotePathString(hoistedNoteId); - $el.trigger("autocomplete:noteselected", [suggestion]); $el.autocomplete("close"); - break; + $el.trigger("autocomplete:noteselected", [suggestion]); + return; } - case SuggestionAction.CreateNoteIntoPath: - case SuggestionAction.CreateAndLinkNoteIntoPath: { - if (!suggestion.parentNoteId) return; - + case SuggestionAction.CreateNoteIntoPath: { + if (!suggestion.parentNoteId) { + console.warn("Missing parentNoteId for CreateNoteIntoPath"); + return; + } const { note } = await noteCreateService.createNote( { - parentNoteUrl: suggestion.parentNoteId, target: "into", + parentNoteUrl: suggestion.parentNoteId, title: suggestion.noteTitle, activate: true, promptForType: true, }, ); - if (!note) return; + if (!note) break; const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId; suggestion.notePath = note?.getBestNotePathString(hoistedNoteId); - - $el.trigger("autocomplete:noteselected", [suggestion]); - $el.autocomplete("close"); break; } + case SuggestionAction.CreateAndLinkNoteIntoPath: { + if (!suggestion.parentNoteId) { + console.warn("Missing parentNoteId for CreateNoteIntoPath"); + return; + } + const { note } = await noteCreateService.createNote( + { + target: "into", + parentNoteUrl: suggestion.parentNoteId, + title: suggestion.noteTitle, + activate: false, + promptForType: true, + } + ); + + if (!note) break; + + const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId; + suggestion.notePath = note?.getBestNotePathString(hoistedNoteId); + $el.autocomplete("close"); + $el.trigger("autocomplete:noteselected", [suggestion]); + return; + } + case SuggestionAction.SearchNotes: { const searchString = suggestion.noteTitle; appContext.triggerCommand("searchNotes", { searchString }); @@ -531,13 +569,12 @@ function initNoteAutocomplete($el: JQuery, options?: Options) { } default: { - $el.setSelectedNotePath(suggestion.notePath); - $el.setSelectedExternalLink(null); - $el.autocomplete("val", suggestion.noteTitle); - $el.autocomplete("close"); - $el.trigger("autocomplete:noteselected", [suggestion]); } } + if (suggestion.notePath) { + $el.trigger("autocomplete:noteselected", [suggestion]); + } + $el.autocomplete("close"); }); $el.on("autocomplete:closed", () => { diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx index 91780387d..bed4331cc 100644 --- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx +++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx @@ -253,11 +253,6 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI parentNotePath: string | undefined, action: CreateNoteAction ): Promise => { - if (!parentNotePath) { - console.warn("Missing parentNotePath in createNoteFromCkEditor()"); - return ""; - } - switch (action) { case CreateNoteAction.CreateNoteIntoInbox: case CreateNoteAction.CreateAndLinkNoteIntoInbox: { @@ -265,7 +260,8 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI { target: "inbox", title, - activate: false + activate: false, + promptForType: true, } ); return note?.getBestNotePathString() ?? ""; @@ -273,6 +269,10 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI case CreateNoteAction.CreateNoteIntoPath: case CreateNoteAction.CreateAndLinkNoteIntoPath: { + if (!parentNotePath) { + console.warn("Missing parentNotePath in createNoteFromCkEditor()"); + return ""; + } const resp = await note_create.createNote( { target: "into",