mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 11:02:28 +08:00
feat(autocomplete): display note icon
This commit is contained in:
parent
eb097ec1ea
commit
a9193fdcd4
@ -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
|
||||
};
|
||||
|
@ -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}`
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -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}`
|
||||
};
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user