#176 - Option to index CamelCaseWords

This commit is contained in:
Simon Cambier
2023-03-02 21:32:37 +01:00
parent 0529b978cb
commit 36ccb52982
3 changed files with 34 additions and 6 deletions

View File

@@ -91,14 +91,17 @@ export function getAllIndices(text: string, regex: RegExp): SearchMatch[] {
*/
export function stringsToRegex(strings: string[]): RegExp {
if (!strings.length) return /^$/g
// Default word split is not applied if the user uses the cm-chs-patch plugin
const joined =
'(' +
(getChsSegmenter() ? '' : `^|${SPACE_OR_PUNCTUATION.source}`) +
// Default word split is not applied if the user uses the cm-chs-patch plugin
(getChsSegmenter()
? ''
: // Split on start of line, spaces, punctuation, or capital letters (for camelCase)
settings.splitCamelCase
? `^|${SPACE_OR_PUNCTUATION.source}|[A-Z]`
: `^|${SPACE_OR_PUNCTUATION.source}`) +
')' +
'(' +
strings.map(s => escapeRegex(s)).join('|') +
')'
`(${strings.map(s => escapeRegex(s)).join('|')})`
const reg = new RegExp(`${joined}`, 'giu')
return reg