mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-04 10:09:38 +02:00
Improve auto-complete of hostname values in "My filters"
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1134
Related commit:
- daf464b3c3
This commit is contained in:
parent
cb7ec8ac1c
commit
262a1a044f
@ -49,22 +49,43 @@ const cmEditor = new CodeMirror(document.getElementById('userFilters'), {
|
|||||||
|
|
||||||
uBlockDashboard.patchCodeMirrorEditor(cmEditor);
|
uBlockDashboard.patchCodeMirrorEditor(cmEditor);
|
||||||
|
|
||||||
vAPI.messaging.send('dashboard', {
|
|
||||||
what: 'getAutoCompleteDetails'
|
|
||||||
}).then(response => {
|
|
||||||
if ( response instanceof Object === false ) { return; }
|
|
||||||
const mode = cmEditor.getMode();
|
|
||||||
// TODO: listen to changes in currently opened set of tabs?
|
|
||||||
if ( mode.setHints instanceof Function ) {
|
|
||||||
mode.setHints(response);
|
|
||||||
}
|
|
||||||
mode.parser.expertMode = response.expertMode !== false;
|
|
||||||
});
|
|
||||||
|
|
||||||
let cachedUserFilters = '';
|
let cachedUserFilters = '';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// Add auto-complete ability to the editor.
|
||||||
|
|
||||||
|
{
|
||||||
|
let hintUpdateToken = 0;
|
||||||
|
|
||||||
|
const responseHandler = function(response) {
|
||||||
|
if ( response instanceof Object === false ) { return; }
|
||||||
|
if ( response.hintUpdateToken !== undefined ) {
|
||||||
|
const firstVisit = hintUpdateToken === 0;
|
||||||
|
const mode = cmEditor.getMode();
|
||||||
|
if ( mode.setHints instanceof Function ) {
|
||||||
|
mode.setHints(response, firstVisit);
|
||||||
|
}
|
||||||
|
if ( firstVisit ) {
|
||||||
|
mode.parser.expertMode = response.expertMode !== false;
|
||||||
|
}
|
||||||
|
hintUpdateToken = response.hintUpdateToken;
|
||||||
|
}
|
||||||
|
vAPI.setTimeout(getHints, 2503);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getHints = function() {
|
||||||
|
vAPI.messaging.send('dashboard', {
|
||||||
|
what: 'getAutoCompleteDetails',
|
||||||
|
hintUpdateToken
|
||||||
|
}).then(responseHandler);
|
||||||
|
};
|
||||||
|
|
||||||
|
getHints();
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
const getEditorText = function() {
|
const getEditorText = function() {
|
||||||
const text = cmEditor.getValue().replace(/\s+$/, '');
|
const text = cmEditor.getValue().replace(/\s+$/, '');
|
||||||
return text === '' ? text : text + '\n';
|
return text === '' ? text : text + '\n';
|
||||||
|
@ -361,7 +361,8 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
|
|||||||
style = style.trim();
|
style = style.trim();
|
||||||
return style !== '' ? style : null;
|
return style !== '' ? style : null;
|
||||||
},
|
},
|
||||||
setHints: function(details) {
|
setHints: function(details, firstVisit = false) {
|
||||||
|
if ( Array.isArray(details.redirectResources) ) {
|
||||||
for ( const [ name, desc ] of details.redirectResources ) {
|
for ( const [ name, desc ] of details.redirectResources ) {
|
||||||
const displayText = desc.aliasOf !== ''
|
const displayText = desc.aliasOf !== ''
|
||||||
? `${name} (${desc.aliasOf})`
|
? `${name} (${desc.aliasOf})`
|
||||||
@ -373,14 +374,24 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
|
|||||||
scriptletNames.set(name.slice(0, -3), displayText);
|
scriptletNames.set(name.slice(0, -3), displayText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ( Array.isArray(details.preparseDirectiveTokens)) {
|
||||||
details.preparseDirectiveTokens.forEach(([ a, b ]) => {
|
details.preparseDirectiveTokens.forEach(([ a, b ]) => {
|
||||||
preparseDirectiveTokens.set(a, b);
|
preparseDirectiveTokens.set(a, b);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
if ( Array.isArray(details.preparseDirectiveHints)) {
|
||||||
preparseDirectiveHints.push(...details.preparseDirectiveHints);
|
preparseDirectiveHints.push(...details.preparseDirectiveHints);
|
||||||
|
}
|
||||||
|
if ( Array.isArray(details.originHints) ) {
|
||||||
|
originHints.length = 0;
|
||||||
for ( const hint of details.originHints ) {
|
for ( const hint of details.originHints ) {
|
||||||
originHints.push(hint);
|
originHints.push(hint);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ( firstVisit ) {
|
||||||
initHints();
|
initHints();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
get parser() {
|
get parser() {
|
||||||
return parser;
|
return parser;
|
||||||
|
@ -1201,13 +1201,17 @@ const onMessage = function(request, sender, callback) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'getAutoCompleteDetails':
|
case 'getAutoCompleteDetails':
|
||||||
response = {
|
response = {};
|
||||||
redirectResources: µb.redirectEngine.getResourceDetails(),
|
if ( request.hintUpdateToken === 0 ) {
|
||||||
preparseDirectiveTokens: µb.preparseDirectives.getTokens(),
|
response.redirectResources = µb.redirectEngine.getResourceDetails();
|
||||||
preparseDirectiveHints: µb.preparseDirectives.getHints(),
|
response.preparseDirectiveTokens = µb.preparseDirectives.getTokens();
|
||||||
originHints: getOriginHints(),
|
response.preparseDirectiveHints = µb.preparseDirectives.getHints();
|
||||||
expertMode: µb.hiddenSettings.filterAuthorMode,
|
response.expertMode = µb.hiddenSettings.filterAuthorMode;
|
||||||
};
|
}
|
||||||
|
if ( request.hintUpdateToken !== µb.pageStoresToken ) {
|
||||||
|
response.originHints = getOriginHints();
|
||||||
|
response.hintUpdateToken = µb.pageStoresToken;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'getRules':
|
case 'getRules':
|
||||||
|
Loading…
Reference in New Issue
Block a user