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