mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
Auto-complete of origin pattern for ||
-based patterns
Related commit:
- daf464b3c3
This commit is contained in:
parent
8060ddb283
commit
e28c2cc3c6
1 changed files with 14 additions and 11 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue