From ac71d6577a8141f79986b125f96a83eb77a13695 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 21 Mar 2019 19:53:04 -0300 Subject: [PATCH] Visually emphasize directive syntax (`!#if`/`!#endif`) in list viewer/editor --- src/css/codemirror.css | 1 + src/js/codemirror/ubo-static-filtering.js | 29 +++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/css/codemirror.css b/src/css/codemirror.css index 4b06717ee..3d5b7d6f9 100644 --- a/src/css/codemirror.css +++ b/src/css/codemirror.css @@ -18,6 +18,7 @@ } .cm-s-default .cm-comment { color: #777; } +.cm-directive { color: #333; font-weight: bold; } .cm-staticext { color: #008; } .cm-staticnetBlock { color: #800; } .cm-staticnetAllow { color: #004f00; } diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index b2177ec90..5bfb54716 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -24,28 +24,29 @@ 'use strict'; CodeMirror.defineMode("ubo-static-filtering", function() { - var reComment1 = /^\s*!/; - var reComment2 = /^\s*#/; - var reExt = /^(\s*[^#]*)(#@?(?:\$\??|\?)?#)(.+)$/; - var reNet = /^(.*?)(?:(\$)([^$]+)?)?$/; - var reNetAllow = /^\s*@@/; - var lineStyle = null; - var lineMatches = null; + const reDirective = /^\s*!#(?:if|endif)\b/; + const reComment1 = /^\s*!/; + const reComment2 = /^\s*#/; + const reExt = /^(\s*[^#]*)(#@?(?:\$\??|\?)?#)(.+)$/; + const reNet = /^(.*?)(?:(\$)([^$]+)?)?$/; + const reNetAllow = /^\s*@@/; + let lineStyle = null; + let lineMatches = null; - var lineStyles = new Map([ + const lineStyles = new Map([ [ 'staticext', [ '', 'staticOpt', '' ] ], [ 'staticnetAllow', [ '', 'staticOpt', '' ] ], [ 'staticnetBlock', [ '', 'staticOpt', '' ] ], ]); - var styleFromStream = function(stream) { - for ( var i = 1, l = 0; i < lineMatches.length; i++ ) { + const styleFromStream = function(stream) { + for ( let i = 1, l = 0; i < lineMatches.length; i++ ) { if ( typeof lineMatches[i] !== 'string' ) { continue; } l += lineMatches[i].length; if ( stream.pos < l ) { stream.pos = l; - var style = lineStyle; - var xstyle = lineStyles.get(style)[i-1]; + let style = lineStyle; + const xstyle = lineStyles.get(style)[i-1]; if ( xstyle !== '' ) { style += ' ' + xstyle; } return style; } @@ -62,6 +63,10 @@ CodeMirror.defineMode("ubo-static-filtering", function() { } else if ( lineStyle !== null ) { return styleFromStream(stream); } + if ( reDirective.test(stream.string) ) { + stream.skipToEnd(); + return 'directive'; + } if ( reComment1.test(stream.string) ) { stream.skipToEnd(); return 'comment';