In-file search ok

This commit is contained in:
Simon Cambier
2022-04-18 22:01:15 +02:00
parent 47b30b5c62
commit f6c3f9b580
8 changed files with 133 additions and 138 deletions

View File

@@ -53,21 +53,6 @@ export function getAllIndices(text: string, regex: RegExp): SearchMatch[] {
.filter(isSearchMatch)
}
// export function getAllIndices(text: string, terms: string[]): SearchMatch[] {
// let matches: SearchMatch[] = []
// for (const term of terms) {
// matches = [
// ...matches,
// ...[...text.matchAll(new RegExp(escapeRegex(term), 'gi'))]
// .map(o => ({ match: o[0], index: o.index }))
// .filter(isSearchMatch),
// ]
// }
// return matches
// // matches.sort((a, b) => b.match.length - a.match.length)
// // return uniqBy(matches, 'index')
// }
export function stringsToRegex(strings: string[]): RegExp {
return new RegExp(strings.map(escapeRegex).join('|'), 'gi')
}
@@ -93,3 +78,7 @@ export function extractHeadingsFromCache(
cache.headings?.filter(h => h.level === level).map(h => h.heading) ?? []
)
}
export function loopIndex(index: number, nbItems: number): number {
return (index + nbItems) % nbItems
}