highlighting: make case-insensitive, support unicode (#3137)
* highlighting: make case-insensitive, support unicode * highlighting: also highlight simplified/normalized form * highlighting: use MDN-recommended escape pattern
This commit is contained in:
parent
80ffd28551
commit
5c07e3ced6
@ -19,7 +19,18 @@ export class ChatMessageHighlightMatcher extends Matcher {
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = str.match(highlightString);
|
||||
const escapedString = highlightString
|
||||
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||
.replace(/\s/g, '\\s');
|
||||
|
||||
const normalizedString = escapedString.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||
|
||||
let highlightRegex = escapedString;
|
||||
if (escapedString !== normalizedString) {
|
||||
highlightRegex = `(?:${escapedString})|(?:${normalizedString})`;
|
||||
}
|
||||
|
||||
const result = str.match(new RegExp(highlightRegex, 'ui'));
|
||||
|
||||
if (!result) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user