fix(note_autocomplete): fix attributes not linking

This commit is contained in:
Jakob Schlanstedt 2025-10-30 19:58:02 +01:00
parent d3db48c99b
commit 77a014109e
2 changed files with 70 additions and 33 deletions

View File

@ -463,67 +463,105 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, 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<HTMLElement>, 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", () => {

View File

@ -253,11 +253,6 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
parentNotePath: string | undefined,
action: CreateNoteAction
): Promise<string> => {
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",