mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
Improve auto-completion in _"My filters"_ editor
This commit is contained in:
parent
a86e804c9c
commit
e4a7df3fd9
1 changed files with 82 additions and 16 deletions
|
@ -443,23 +443,89 @@ const initHints = function() {
|
|||
if ( text.startsWith(seed) === false ) { continue; }
|
||||
out.push(hint);
|
||||
}
|
||||
// If no match, try again with a different heuristic
|
||||
if ( out.length === 0 ) {
|
||||
for ( const hint of hints ) {
|
||||
const text = hint instanceof Object
|
||||
? hint.displayText || hint.text
|
||||
: hint;
|
||||
if ( seedLeft.length === 1 ) {
|
||||
if ( text.startsWith(seedLeft) === false ) { continue; }
|
||||
} else if ( text.includes(seed) === false ) { continue; }
|
||||
out.push(hint);
|
||||
}
|
||||
if ( out.length !== 0 ) {
|
||||
return {
|
||||
from: { line: cursor.line, ch: cursor.ch - seedLeft.length },
|
||||
to: { line: cursor.line, ch: cursor.ch + seedRight.length },
|
||||
list: out,
|
||||
};
|
||||
}
|
||||
// If no match, try again with a different heuristic: valid hints are
|
||||
// those matching left seed, not matching right seed but right seed is
|
||||
// found to be a valid hint. This is to take care of cases like:
|
||||
//
|
||||
// *$script,redomain=example.org
|
||||
// ^
|
||||
// + cursor position
|
||||
//
|
||||
// In such case, [ redirect=, redirect-rule= ] should be returned
|
||||
// as valid hints.
|
||||
for ( const hint of hints ) {
|
||||
const text = hint instanceof Object
|
||||
? hint.displayText || hint.text
|
||||
: hint;
|
||||
if ( seedLeft.length === 0 ) { continue; }
|
||||
if ( text.startsWith(seedLeft) === false ) { continue; }
|
||||
if ( hints.includes(seedRight) === false ) { continue; }
|
||||
out.push(hint);
|
||||
}
|
||||
if ( out.length !== 0 ) {
|
||||
return {
|
||||
from: { line: cursor.line, ch: cursor.ch - seedLeft.length },
|
||||
to: { line: cursor.line, ch: cursor.ch },
|
||||
list: out,
|
||||
};
|
||||
}
|
||||
// If no match, try again with a different heuristic: valid hints are
|
||||
// those containing seed as a substring. This is to take care of cases
|
||||
// like:
|
||||
//
|
||||
// *$script,redirect=gif
|
||||
// ^
|
||||
// + cursor position
|
||||
//
|
||||
// In such case, [ 1x1.gif, 1x1-transparent.gif ] should be returned
|
||||
// as valid hints.
|
||||
for ( const hint of hints ) {
|
||||
const text = hint instanceof Object
|
||||
? hint.displayText || hint.text
|
||||
: hint;
|
||||
if ( seedLeft.length === 1 ) {
|
||||
if ( text.startsWith(seedLeft) === false ) { continue; }
|
||||
} else if ( text.includes(seed) === false ) { continue; }
|
||||
out.push(hint);
|
||||
}
|
||||
if ( out.length !== 0 ) {
|
||||
return {
|
||||
from: { line: cursor.line, ch: cursor.ch - seedLeft.length },
|
||||
to: { line: cursor.line, ch: cursor.ch + seedRight.length },
|
||||
list: out,
|
||||
};
|
||||
}
|
||||
// If still no match, try again with a different heuristic: valid hints
|
||||
// are those containing left seed as a substring. This is to take care
|
||||
// of cases like:
|
||||
//
|
||||
// *$script,redirect=gifdomain=example.org
|
||||
// ^
|
||||
// + cursor position
|
||||
//
|
||||
// In such case, [ 1x1.gif, 1x1-transparent.gif ] should be returned
|
||||
// as valid hints.
|
||||
for ( const hint of hints ) {
|
||||
const text = hint instanceof Object
|
||||
? hint.displayText || hint.text
|
||||
: hint;
|
||||
if ( text.includes(seedLeft) === false ) { continue; }
|
||||
out.push(hint);
|
||||
}
|
||||
if ( out.length !== 0 ) {
|
||||
return {
|
||||
from: { line: cursor.line, ch: cursor.ch - seedLeft.length },
|
||||
to: { line: cursor.line, ch: cursor.ch },
|
||||
list: out,
|
||||
};
|
||||
}
|
||||
return {
|
||||
from: { line: cursor.line, ch: cursor.ch - seedLeft.length },
|
||||
to: { line: cursor.line, ch: cursor.ch + seedRight.length },
|
||||
list: out,
|
||||
};
|
||||
};
|
||||
|
||||
const getOriginHints = function(cursor, line, suffix = '') {
|
||||
|
|
Loading…
Reference in a new issue