Merge pull request #337 from Morfent/highlights

SyntaxError handling when adding regex highlights
This commit is contained in:
Guangcong Luo 2015-02-21 14:11:42 -06:00
commit b16d753ef5

View File

@ -570,8 +570,16 @@
switch (targets[0]) {
case 'add':
for (var i=1, len=targets.length; i<len; i++) {
highlights.push(targets[i].trim());
if (/[\\^$*+?()|{}[\]]/.test(targets[i])) {
// Catch any errors thrown by newly added regular expressions so they don't break the entire highlight list
try {
new RegExp(targets[i]);
} catch (e) {
return this.add(e.message.substr(0, 28) === 'Invalid regular expression: ' ? e.message : 'Invalid regular expression: /' + targets[i] + '/: ' + e.message);
}
}
}
highlights = highlights.concat(targets.slice(1));
this.add("Now highlighting on: " + highlights.join(', '));
// We update the regex
app.highlightRegExp = new RegExp('\\b('+highlights.join('|')+')\\b', 'i');