mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
fix(note_autocomplete): fix attributes not linking
This commit is contained in:
parent
d3db48c99b
commit
77a014109e
@ -463,67 +463,105 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
|||||||
|
|
||||||
// TODO: Types fail due to "autocomplete:selected" not being registered in type definitions.
|
// 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 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) {
|
switch (suggestion.action) {
|
||||||
case SuggestionAction.Command: {
|
case SuggestionAction.Command: {
|
||||||
$el.autocomplete("close");
|
|
||||||
$el.trigger("autocomplete:commandselected", [suggestion]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SuggestionAction.ExternalLink: {
|
case SuggestionAction.ExternalLink: {
|
||||||
$el.setSelectedNotePath(null);
|
|
||||||
$el.setSelectedExternalLink(suggestion.externalLink);
|
|
||||||
$el.autocomplete("val", suggestion.externalLink);
|
|
||||||
$el.autocomplete("close");
|
|
||||||
$el.trigger("autocomplete:externallinkselected", [suggestion]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SuggestionAction.CreateNoteIntoInbox:
|
// --- CREATE NOTE INTO INBOX ---
|
||||||
case SuggestionAction.CreateAndLinkNoteIntoInbox: {
|
case SuggestionAction.CreateNoteIntoInbox: {
|
||||||
const { note } = await noteCreateService.createNote(
|
const { note } = await noteCreateService.createNote(
|
||||||
{
|
{
|
||||||
target: "inbox",
|
target: "inbox",
|
||||||
title: suggestion.noteTitle,
|
title: suggestion.noteTitle,
|
||||||
activate: true,
|
activate: true,
|
||||||
promptForType: 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;
|
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
|
||||||
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
|
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
|
||||||
|
|
||||||
$el.trigger("autocomplete:noteselected", [suggestion]);
|
|
||||||
$el.autocomplete("close");
|
$el.autocomplete("close");
|
||||||
break;
|
$el.trigger("autocomplete:noteselected", [suggestion]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SuggestionAction.CreateNoteIntoPath:
|
case SuggestionAction.CreateNoteIntoPath: {
|
||||||
case SuggestionAction.CreateAndLinkNoteIntoPath: {
|
if (!suggestion.parentNoteId) {
|
||||||
if (!suggestion.parentNoteId) return;
|
console.warn("Missing parentNoteId for CreateNoteIntoPath");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const { note } = await noteCreateService.createNote(
|
const { note } = await noteCreateService.createNote(
|
||||||
{
|
{
|
||||||
parentNoteUrl: suggestion.parentNoteId,
|
|
||||||
target: "into",
|
target: "into",
|
||||||
|
parentNoteUrl: suggestion.parentNoteId,
|
||||||
title: suggestion.noteTitle,
|
title: suggestion.noteTitle,
|
||||||
activate: true,
|
activate: true,
|
||||||
promptForType: true,
|
promptForType: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!note) return;
|
if (!note) break;
|
||||||
|
|
||||||
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
|
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
|
||||||
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
|
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
|
||||||
|
|
||||||
$el.trigger("autocomplete:noteselected", [suggestion]);
|
|
||||||
$el.autocomplete("close");
|
|
||||||
break;
|
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: {
|
case SuggestionAction.SearchNotes: {
|
||||||
const searchString = suggestion.noteTitle;
|
const searchString = suggestion.noteTitle;
|
||||||
appContext.triggerCommand("searchNotes", { searchString });
|
appContext.triggerCommand("searchNotes", { searchString });
|
||||||
@ -531,13 +569,12 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
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", () => {
|
$el.on("autocomplete:closed", () => {
|
||||||
|
|||||||
@ -253,11 +253,6 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
|||||||
parentNotePath: string | undefined,
|
parentNotePath: string | undefined,
|
||||||
action: CreateNoteAction
|
action: CreateNoteAction
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
if (!parentNotePath) {
|
|
||||||
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case CreateNoteAction.CreateNoteIntoInbox:
|
case CreateNoteAction.CreateNoteIntoInbox:
|
||||||
case CreateNoteAction.CreateAndLinkNoteIntoInbox: {
|
case CreateNoteAction.CreateAndLinkNoteIntoInbox: {
|
||||||
@ -265,7 +260,8 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
|||||||
{
|
{
|
||||||
target: "inbox",
|
target: "inbox",
|
||||||
title,
|
title,
|
||||||
activate: false
|
activate: false,
|
||||||
|
promptForType: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return note?.getBestNotePathString() ?? "";
|
return note?.getBestNotePathString() ?? "";
|
||||||
@ -273,6 +269,10 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
|||||||
|
|
||||||
case CreateNoteAction.CreateNoteIntoPath:
|
case CreateNoteAction.CreateNoteIntoPath:
|
||||||
case CreateNoteAction.CreateAndLinkNoteIntoPath: {
|
case CreateNoteAction.CreateAndLinkNoteIntoPath: {
|
||||||
|
if (!parentNotePath) {
|
||||||
|
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
const resp = await note_create.createNote(
|
const resp = await note_create.createNote(
|
||||||
{
|
{
|
||||||
target: "into",
|
target: "into",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user