From 069e307ec4580e9d82df1abbf013589d8f85eed0 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 17 Apr 2025 20:49:45 +0300 Subject: [PATCH] refactor(note_autocomplete): icon as separate field --- src/public/app/services/note_autocomplete.ts | 4 +++- src/routes/api/autocomplete.ts | 3 ++- src/services/search/services/search.ts | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/public/app/services/note_autocomplete.ts b/src/public/app/services/note_autocomplete.ts index a92c241a6..c9e39785e 100644 --- a/src/public/app/services/note_autocomplete.ts +++ b/src/public/app/services/note_autocomplete.ts @@ -21,6 +21,7 @@ function getSearchDelay(notesCount: number): number { } let searchDelay = getSearchDelay(notesCount); +// TODO: Deduplicate with server. export interface Suggestion { noteTitle?: string; externalLink?: string; @@ -29,6 +30,7 @@ export interface Suggestion { highlightedNotePathTitle?: string; action?: string | "create-note" | "search-notes" | "external-link"; parentNoteId?: string; + icon?: string; } interface Options { @@ -262,7 +264,7 @@ function initNoteAutocomplete($el: JQuery, options?: Options) { }, displayKey: "notePathTitle", templates: { - suggestion: (suggestion) => suggestion.highlightedNotePathTitle + suggestion: (suggestion) => ` ${suggestion.highlightedNotePathTitle}` }, // we can't cache identical searches because notes can be created / renamed, new recent notes can be added cache: false diff --git a/src/routes/api/autocomplete.ts b/src/routes/api/autocomplete.ts index bbe990bcd..459555968 100644 --- a/src/routes/api/autocomplete.ts +++ b/src/routes/api/autocomplete.ts @@ -75,7 +75,8 @@ function getRecentNotes(activeNoteId: string) { notePath: rn.notePath, noteTitle: title, notePathTitle, - highlightedNotePathTitle: ` ${notePathTitle}` + highlightedNotePathTitle: utils.escapeHtml(notePathTitle), + icon: icon ?? "bx bx-note" }; }); } diff --git a/src/services/search/services/search.ts b/src/services/search/services/search.ts index 5e9b4bb9d..97ff54393 100644 --- a/src/services/search/services/search.ts +++ b/src/services/search/services/search.ts @@ -359,7 +359,8 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) { notePath: result.notePath, noteTitle: title, notePathTitle: `${icon} ${result.notePathTitle}`, - highlightedNotePathTitle: ` ${result.highlightedNotePathTitle}` + highlightedNotePathTitle: result.highlightedNotePathTitle, + icon: icon ?? "bx bx-note" }; }); }