Auto-complete of origin pattern for ||-based patterns

Related commit:
- daf464b3c3
This commit is contained in:
Raymond Hill 2020-12-15 08:27:59 -05:00
parent 8060ddb283
commit e28c2cc3c6
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -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);