diff --git a/src/runtime/utils/fuse.ts b/src/runtime/utils/fuse.ts index d6ca245a..02745817 100644 --- a/src/runtime/utils/fuse.ts +++ b/src/runtime/utils/fuse.ts @@ -33,12 +33,17 @@ function truncateHTMLFromStart(html: string, maxLength: number) { } export function highlight(item: T & { matches?: FuseResult['matches'] }, searchTerm: string, forceKey?: string, omitKeys?: string[]) { - const generateHighlightedText = (value: FuseResultMatch['value'], indices: FuseResultMatch['indices'] = []) => { + function generateHighlightedText(value: FuseResultMatch['value'], indices: FuseResultMatch['indices'] = []) { value = value || '' let content = '' let nextUnhighlightedRegionStartingIndex = 0 indices.forEach((region) => { + // skip if region is a single character + if (region.length === 2 && region[0] === region[1]) { + return + } + const lastIndiceNextIndex = region[1] + 1 const isMatched = (lastIndiceNextIndex - region[0]) >= searchTerm.length