Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 069e307

Browse files
committed
refactor(note_autocomplete): icon as separate field
1 parent 482243b commit 069e307

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/public/app/services/note_autocomplete.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function getSearchDelay(notesCount: number): number {
2121
}
2222
let searchDelay = getSearchDelay(notesCount);
2323

24+
// TODO: Deduplicate with server.
2425
export interface Suggestion {
2526
noteTitle?: string;
2627
externalLink?: string;
@@ -29,6 +30,7 @@ export interface Suggestion {
2930
highlightedNotePathTitle?: string;
3031
action?: string | "create-note" | "search-notes" | "external-link";
3132
parentNoteId?: string;
33+
icon?: string;
3234
}
3335

3436
interface Options {
@@ -262,7 +264,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
262264
},
263265
displayKey: "notePathTitle",
264266
templates: {
265-
suggestion: (suggestion) => suggestion.highlightedNotePathTitle
267+
suggestion: (suggestion) => `<span class="${suggestion.icon ?? "bx bx-note"}"></span> ${suggestion.highlightedNotePathTitle}`
266268
},
267269
// we can't cache identical searches because notes can be created / renamed, new recent notes can be added
268270
cache: false

src/routes/api/autocomplete.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ function getRecentNotes(activeNoteId: string) {
7575
notePath: rn.notePath,
7676
noteTitle: title,
7777
notePathTitle,
78-
highlightedNotePathTitle: `<span class="${icon ?? "bx bx-note"}"></span> ${notePathTitle}`
78+
highlightedNotePathTitle: utils.escapeHtml(notePathTitle),
79+
icon: icon ?? "bx bx-note"
7980
};
8081
});
8182
}

src/services/search/services/search.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) {
359359
notePath: result.notePath,
360360
noteTitle: title,
361361
notePathTitle: `${icon} ${result.notePathTitle}`,
362-
highlightedNotePathTitle: `<span class="${icon ?? "bx bx-note"}"></span> ${result.highlightedNotePathTitle}`
362+
highlightedNotePathTitle: result.highlightedNotePathTitle,
363+
icon: icon ?? "bx bx-note"
363364
};
364365
});
365366
}

0 commit comments

Comments
 (0)