From 38e1bbbe68586d88f8d385d93b4c45b086c1eea0 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 16 Oct 2020 10:06:00 -0400 Subject: [PATCH] Better word selection for static network filters Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1134 Double-clicking on... ... a filter option will cause the option to be wholly selected, including `=[value]` if present; ... a value assigned to a filter option will cause the value to be wholly selected, except when the value is a hostname/entity, in which case all the labels from the cursor position to the right-most label will be selected. --- src/js/codemirror/ubo-static-filtering.js | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index 5821af7c4..3e3f583c3 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -633,7 +633,7 @@ CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => { } // Better word selection for cosmetic filters - if ( /\bext\b/.test(token) ) { + else if ( /\bext\b/.test(token) ) { if ( /\bvalue\b/.test(token) ) { const l = /[^,.]*$/i.exec(s.slice(0, ch)); const r = /^[^#,]*/i.exec(s.slice(ch)); @@ -641,8 +641,7 @@ CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => { beg = l.index; end = ch + r[0].length; } - } - if ( /\bvariable\b/.test(token) ) { + } else if ( /\bvariable\b/.test(token) ) { const l = /[#.]?[a-z0-9_-]+$/i.exec(s.slice(0, ch)); const r = /^[a-z0-9_-]+/i.exec(s.slice(ch)); if ( l && r ) { @@ -655,7 +654,24 @@ CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => { } } - // TODO: add more convenient word-matching cases here + // Better word selection for network filters + else if ( /\bnet\b/.test(token) ) { + if ( /\bvalue\b/.test(token) ) { + const l = /[^,.=|]*$/i.exec(s.slice(0, ch)); + const r = /^[^#,|]*/i.exec(s.slice(ch)); + if ( l && r ) { + beg = l.index; + end = ch + r[0].length; + } + } else if ( /\bdef\b/.test(token) ) { + const l = /[a-z0-9-]+$/i.exec(s.slice(0, ch)); + const r = /^[^,]*=[^,]+/i.exec(s.slice(ch)); + if ( l && r ) { + beg = l.index; + end = ch + r[0].length; + } + } + } if ( beg === undefined ) { return Pass; } cm.setSelection(