From ca80d2826bfd92a3081f20da8ba60138509a183b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 15 Mar 2020 08:15:17 -0400 Subject: [PATCH] Add indentation requirement for line continuation Related commit: - https://github.com/gorhill/uBlock/commit/703c525b01aa This adds an indentation requirement for line continuation to take place. The conditions are now as follow: - Current line ends with ` \`: ASCII space + backslash - Next line starts with ` `: four ASCII spaces --- src/js/codemirror/ubo-static-filtering.js | 1 + src/js/storage.js | 1 + src/js/utils.js | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index 655caa462..bc71dfc30 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -121,6 +121,7 @@ CodeMirror.defineMode("ubo-static-filtering", function() { if ( line.endsWith(' \\') ) { do { line = stream.lookAhead(lines.length); + if ( line.startsWith(' ') === false ) { break; } lines.push(line); } while ( line.endsWith(' \\') ); } diff --git a/src/js/storage.js b/src/js/storage.js index 7130ee28a..8ccac6240 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -808,6 +808,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => { if ( line.length === 0 ) { continue; } while ( line.endsWith(' \\') ) { + if ( lineIter.peek(4) !== ' ' ) { break; } line = line.slice(0, -2).trim() + lineIter.next().trim(); } diff --git a/src/js/utils.js b/src/js/utils.js index 7a4765d1a..fada05f59 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -242,6 +242,10 @@ this.offset = lineEnd + 1; return line; } + peek(n) { + const offset = this.offset; + return this.text.slice(offset, offset + n); + } charCodeAt(offset) { return this.text.charCodeAt(this.offset + offset); }