diff --git a/src/css/codemirror.css b/src/css/codemirror.css index 9b78ca221..61c7b1fde 100644 --- a/src/css/codemirror.css +++ b/src/css/codemirror.css @@ -26,6 +26,12 @@ .cm-s-default .cm-string-2 { color: #930; } .cm-s-default .cm-comment { color: #777; } .cm-s-default .cm-keyword { color: #90b; } +.cm-s-default .cm-regex { + text-underline-position: under; + text-decoration-color: darkgray; + text-decoration-style: solid; + text-decoration-line: underline; + } .cm-s-default .cm-error, .CodeMirror-linebackground.error { background-color: #ff000018; diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index 6b2173dd0..999b545c0 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -104,11 +104,17 @@ CodeMirror.defineMode("ubo-static-filtering", function() { parserSlot >= parser.patternSpan.i && parserSlot < parser.patternRightAnchorSpan.i ) { - if ( (parser.slices[parserSlot] & (parser.BITAsterisk | parser.BITCaret)) !== 0 ) { + const isRegex = parser.patternIsRegex(); + if ( + (isRegex === false) && + (parser.slices[parserSlot] & (parser.BITAsterisk | parser.BITCaret)) !== 0 + ) { stream.pos += parser.slices[parserSlot+2]; parserSlot += 3; return 'keyword strong'; } + let style = 'variable'; + if ( isRegex ) { style += ' regex'; } const nextSlot = parser.skipUntil( parserSlot, parser.patternRightAnchorSpan.i, @@ -116,7 +122,7 @@ CodeMirror.defineMode("ubo-static-filtering", function() { ); stream.pos = parser.slices[nextSlot+1]; parserSlot = nextSlot; - return 'variable'; + return style; } if ( parserSlot === parser.optionsAnchorSpan.i && diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index a61801872..93bbd0457 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -350,11 +350,10 @@ const Parser = class { // https://github.com/gorhill/uBlock/issues/952 // AdGuard-specific `$$` filters => unsupported. if ( this.findFirstOdd(0, BITHostname | BITComma | BITAsterisk) === i ) { + this.flavorBits |= BITFlavorError; if ( this.interactive ) { this.markSlices(i, i+3, BITError); } - this.allBits |= BITError; - this.flavorBits |= BITFlavorError; } else { this.splitSlot(i, l - 1); i += 3; @@ -568,8 +567,7 @@ const Parser = class { void new RegExp(this.getNetPattern()); } catch (ex) { - const { i, l } = this.patternSpan; - this.markSlices(i, i + l, BITError); + this.markSpan(this.patternSpan, BITError); } } else if ( this.patternIsDubious() ) { this.markSpan(this.patternSpan, BITError); @@ -979,7 +977,7 @@ const Parser = class { } hasError() { - return hasBits(this.allBits, BITError); + return hasBits(this.flavorBits, BITFlavorError); } };