Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(autocomplete): display note icon
Elian Dorana9193fdcd4ad
diff --git a/src/becca/becca_service.ts b/src/becca/becca_service.tsindex ab6838a780..3304fcd1ba 100644--- a/src/becca/becca_service.ts+++ b/src/becca/becca_service.ts@@ -40,6 +40,33 @@ function getNoteTitle(childNoteId: string, parentNoteId?: string) {return `${branch && branch.prefix ? `${branch.prefix} - ` : ""}${title}`;}+/**+ * Similar to {@link getNoteTitle}, but also returns the icon class of the note.+ *+ * @returns An object containing the title and icon class of the note.+ */+function getNoteTitleAndIcon(childNoteId: string, parentNoteId?: string) {+ const childNote = becca.notes[childNoteId];+ const parentNote = parentNoteId ? becca.notes[parentNoteId] : null;++ if (!childNote) {+ log.info(`Cannot find note '${childNoteId}'`);+ return {+ title: "[error fetching title]"+ }+ }++ const title = childNote.getTitleOrProtected();+ const icon = childNote.getLabelValue("iconClass");++ const branch = parentNote ? becca.getBranchFromChildAndParent(childNote.noteId, parentNote.noteId) : null;++ return {+ icon,+ title: `${branch && branch.prefix ? `${branch.prefix} - ` : ""}${title}`+ }+}+function getNoteTitleArrayForPath(notePathArray: string[]) {if (!notePathArray || !Array.isArray(notePathArray)) {throw new Error(`${notePathArray} is not an array.`);@@ -84,6 +111,7 @@ function getNoteTitleForPath(notePathArray: string[]) {export default {getNoteTitle,+ getNoteTitleAndIcon,getNoteTitleForPath,isNotePathArchived};diff --git a/src/routes/api/autocomplete.ts b/src/routes/api/autocomplete.tsindex 27d2e69f32..a357ca4b3a 100644--- a/src/routes/api/autocomplete.ts+++ b/src/routes/api/autocomplete.ts@@ -67,14 +67,14 @@ function getRecentNotes(activeNoteId: string) {return recentNotes.map((rn) => {const notePathArray = rn.notePath.split("/");- const noteTitle = beccaService.getNoteTitle(notePathArray[notePathArray.length - 1]);+ const { title, icon } = beccaService.getNoteTitleAndIcon(notePathArray[notePathArray.length - 1]);const notePathTitle = beccaService.getNoteTitleForPath(notePathArray);return {notePath: rn.notePath,- noteTitle,+ noteTitle: title,notePathTitle,- highlightedNotePathTitle: utils.escapeHtml(notePathTitle)+ highlightedNotePathTitle: `<span class="${icon ?? "bx bx-note"}"></span> ${notePathTitle}`};});}diff --git a/src/services/search/services/search.ts b/src/services/search/services/search.tsindex 745562cd79..5e9b4bb9d2 100644--- a/src/services/search/services/search.ts+++ b/src/services/search/services/search.ts@@ -354,11 +354,12 @@ function searchNotesForAutocomplete(query: string, fastSearch: boolean = true) {highlightSearchResults(trimmed, searchContext.highlightedTokens, searchContext.ignoreInternalAttributes);return trimmed.map((result) => {+ const { title, icon } = beccaService.getNoteTitleAndIcon(result.noteId);return {notePath: result.notePath,- noteTitle: beccaService.getNoteTitle(result.noteId),- notePathTitle: result.notePathTitle,- highlightedNotePathTitle: result.highlightedNotePathTitle+ noteTitle: title,+ notePathTitle: `${icon} ${result.notePathTitle}`,+ highlightedNotePathTitle: `<span class="${icon ?? "bx bx-note"}"></span> ${result.highlightedNotePathTitle}`};});}