mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +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}`;
 | 
					    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[]) {
 | 
					function getNoteTitleArrayForPath(notePathArray: string[]) {
 | 
				
			||||||
    if (!notePathArray || !Array.isArray(notePathArray)) {
 | 
					    if (!notePathArray || !Array.isArray(notePathArray)) {
 | 
				
			||||||
        throw new Error(`${notePathArray} is not an array.`);
 | 
					        throw new Error(`${notePathArray} is not an array.`);
 | 
				
			||||||
@ -84,6 +111,7 @@ function getNoteTitleForPath(notePathArray: string[]) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
    getNoteTitle,
 | 
					    getNoteTitle,
 | 
				
			||||||
 | 
					    getNoteTitleAndIcon,
 | 
				
			||||||
    getNoteTitleForPath,
 | 
					    getNoteTitleForPath,
 | 
				
			||||||
    isNotePathArchived
 | 
					    isNotePathArchived
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -67,14 +67,14 @@ function getRecentNotes(activeNoteId: string) {
 | 
				
			|||||||
    return recentNotes.map((rn) => {
 | 
					    return recentNotes.map((rn) => {
 | 
				
			||||||
        const notePathArray = rn.notePath.split("/");
 | 
					        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);
 | 
					        const notePathTitle = beccaService.getNoteTitleForPath(notePathArray);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            notePath: rn.notePath,
 | 
					            notePath: rn.notePath,
 | 
				
			||||||
            noteTitle,
 | 
					            noteTitle: title,
 | 
				
			||||||
            notePathTitle,
 | 
					            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);
 | 
					    highlightSearchResults(trimmed, searchContext.highlightedTokens, searchContext.ignoreInternalAttributes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return trimmed.map((result) => {
 | 
					    return trimmed.map((result) => {
 | 
				
			||||||
 | 
					        const { title, icon } = beccaService.getNoteTitleAndIcon(result.noteId);
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            notePath: result.notePath,
 | 
					            notePath: result.notePath,
 | 
				
			||||||
            noteTitle: beccaService.getNoteTitle(result.noteId),
 | 
					            noteTitle: title,
 | 
				
			||||||
            notePathTitle: result.notePathTitle,
 | 
					            notePathTitle: `${icon} ${result.notePathTitle}`,
 | 
				
			||||||
            highlightedNotePathTitle: result.highlightedNotePathTitle
 | 
					            highlightedNotePathTitle: `<span class="${icon ?? "bx bx-note"}"></span> ${result.highlightedNotePathTitle}`
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user