fix autocomplete after var(, autocompleteOnTyping

This commit is contained in:
tophf 2021-01-07 14:50:07 +03:00
parent 312f444ec7
commit 39e03b0a9f

View File

@ -1,4 +1,5 @@
/* global CodeMirror */
/* global cmFactory */
/* global debounce */// toolbox.js
/* global editor */
/* global prefs */
@ -19,17 +20,20 @@
const originalHelper = CodeMirror.hint.css || (() => {});
let cssProps, cssMedia;
CodeMirror.defineOption('autocompleteOnTyping', prefs.get('editor.autocompleteOnTyping'),
(cm, value) => {
cm[value ? 'on' : 'off']('changes', autocompleteOnTyping);
cm[value ? 'on' : 'off']('pick', autocompletePicked);
});
const aot = prefs.get('editor.autocompleteOnTyping');
CodeMirror.defineOption('autocompleteOnTyping', aot, aotToggled);
if (aot) cmFactory.globalSetOption('autocompleteOnTyping', true);
CodeMirror.registerHelper('hint', 'css', helper);
CodeMirror.registerHelper('hint', 'stylus', helper);
tokenHooks['/'] = tokenizeUsoVariables;
function aotToggled(cm, value) {
cm[value ? 'on' : 'off']('changes', autocompleteOnTyping);
cm[value ? 'on' : 'off']('pick', autocompletePicked);
}
function helper(cm) {
const pos = cm.getCursor();
const {line, ch} = pos;
@ -87,11 +91,15 @@
case '-': // --variable
case '(': // var(
list = str.startsWith('--') || testAt(rxVAR, ch - 4, text)
list = str.startsWith('--') || testAt(rxVAR, ch - 5, text)
? findAllCssVars(cm, left)
: [];
prev += str.startsWith('(');
if (str.startsWith('(')) {
prev++;
leftLC = left.slice(1);
} else {
leftLC = left;
}
break;
case '/': // USO vars