1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-02 17:19:38 +02:00

Improve auto-completion in _"My filters"_ editor

This commit is contained in:
Raymond Hill 2021-12-19 08:17:06 -05:00
parent a86e804c9c
commit e4a7df3fd9
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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 = '') {