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:
John Regan 2023-07-05 14:23:39 -04:00 committed by GitHub
parent 80ffd28551
commit 5c07e3ced6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;