mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-30 11:47:55 +01:00
fix(fuse): prevent indices highlight of a single char
This commit is contained in:
@@ -33,12 +33,17 @@ function truncateHTMLFromStart(html: string, maxLength: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function highlight<T>(item: T & { matches?: FuseResult<T>['matches'] }, searchTerm: string, forceKey?: string, omitKeys?: string[]) {
|
export function highlight<T>(item: T & { matches?: FuseResult<T>['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 || ''
|
value = value || ''
|
||||||
let content = ''
|
let content = ''
|
||||||
let nextUnhighlightedRegionStartingIndex = 0
|
let nextUnhighlightedRegionStartingIndex = 0
|
||||||
|
|
||||||
indices.forEach((region) => {
|
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 lastIndiceNextIndex = region[1] + 1
|
||||||
const isMatched = (lastIndiceNextIndex - region[0]) >= searchTerm.length
|
const isMatched = (lastIndiceNextIndex - region[0]) >= searchTerm.length
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user