From e28c2cc3c6e4d9e4c34327947595622f99878956 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 15 Dec 2020 08:27:59 -0500 Subject: [PATCH] Auto-complete of origin pattern for `||`-based patterns Related commit: - https://github.com/gorhill/uBlock/commit/daf464b3c30e9c0c5f5991ba1bde8f9dca1d7078 --- src/js/codemirror/ubo-static-filtering.js | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index 1b987b22b..b7d329521 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -455,18 +455,28 @@ const initHints = function() { }; }; - const getOriginHints = function(cursor, line) { + const getOriginHints = function(cursor, line, suffix = '') { const beg = cursor.ch; const matchLeft = /[^,|=~]*$/.exec(line.slice(0, beg)); const matchRight = /^[^#,|]*/.exec(line.slice(beg)); if ( matchLeft === null || matchRight === null ) { return; } const hints = []; for ( const text of originHints ) { - hints.push(text); + hints.push(text + suffix); } return pickBestHints(cursor, matchLeft[0], matchRight[0], hints); }; + const getNetPatternHints = function(cursor, line) { + if ( /\|\|[\w.-]*$/.test(line.slice(0, cursor.ch)) ) { + return getOriginHints(cursor, line, '^'); + } + // Maybe a static extended filter is meant to be crafted. + if ( /[^\w\x80-\xF4#,.-]/.test(line) === false ) { + return getOriginHints(cursor, line); + } + }; + const getNetOptionHints = function(cursor, seedLeft, seedRight) { const isNegated = seedLeft.startsWith('~'); if ( isNegated ) { @@ -503,16 +513,9 @@ const initHints = function() { const getNetHints = function(cursor, line) { const beg = cursor.ch; - if ( - parser.optionsAnchorSpan.len === 0 && - line.endsWith('$') === false - ) { - if ( /[^\w\x80-\xF4#,.-]/.test(line) === false ) { - return getOriginHints(cursor, line); - } - return; + if ( beg <= parser.slices[parser.optionsAnchorSpan.i+1] ) { + return getNetPatternHints(cursor, line); } - if ( beg < parser.slices[parser.optionsSpan.i+1] ) { return; } const lineBefore = line.slice(0, beg); const lineAfter = line.slice(beg); let matchLeft = /[^$,]*$/.exec(lineBefore);