From 8680bbc0860cd41eb7cd0e94baceb46259acad6a Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 1 Mar 2018 11:26:24 -0500 Subject: [PATCH] fine tuning codemirror styles --- src/css/codemirror.css | 4 +++ .../addon/mode/ubo-static-filtering.js | 33 ++++++++++--------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/css/codemirror.css b/src/css/codemirror.css index cc659107f..5659af129 100644 --- a/src/css/codemirror.css +++ b/src/css/codemirror.css @@ -8,3 +8,7 @@ height: 100%; width: 100%; } +.cm-s-default .cm-comment {color: #777;} +.cm-staticext {color: #008;} +.cm-staticnet.cm-block {color: #800;} +.cm-staticnet.cm-allow {color: #060;} diff --git a/src/lib/codemirror/addon/mode/ubo-static-filtering.js b/src/lib/codemirror/addon/mode/ubo-static-filtering.js index d56d99dee..7509e4860 100644 --- a/src/lib/codemirror/addon/mode/ubo-static-filtering.js +++ b/src/lib/codemirror/addon/mode/ubo-static-filtering.js @@ -24,26 +24,29 @@ 'use strict'; CodeMirror.defineMode("ubo-static-filtering", function() { + var reNotSpace = /\S/; + var reComment = /^(?:!|#[^#@]|#@[^#])/; + var reExt = /^[^#]*#(?:#[^#]|##[^#]|@#)/; + var reNetAllow = /^@@/; + return { token: function(stream) { - if ( stream.sol() === false ) { - return null; - } - stream.eatSpace(); - var c = stream.next(); - if ( c === '!' ) { - stream.skipToEnd(); - return 'comment'; - } - if ( c === '#' ) { - c = stream.next(); - if ( c !== '#' && c !== '@' ) { - stream.skipToEnd(); - return 'comment'; + var style = null; + var pos = stream.string.search(reNotSpace); + if ( pos !== -1 ) { + var s = stream.string.slice(pos); + if ( reComment.test(s) ) { + style = 'comment'; + } else if ( reExt.test(s) ) { + style = 'staticext'; + } else if ( reNetAllow.test(s) ) { + style = 'staticnet allow'; + } else { + style = 'staticnet block'; } } stream.skipToEnd(); - return null; + return style; } }; });