Skip to content

Commit dc20164

Browse files
committed
fix autocomplete inside unknown context
1 parent c0b53dc commit dc20164

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/edit/autocomplete.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const rxCmTopFunc = /^(top|documentTypes|atBlock)/;
1818
const rxCmVarTagColor = /^(variable|tag|error)/;
1919
const rxConsume = /([-\w]*\s*:\s?)?/yu;
2020
const rxCruftAtStart = /^[^\w\s]\s*/;
21-
const rxFilterable = /^(--|[#.\w])\S*\s*$|^@/;
21+
const rxFilterable = /(--|[#.\w])\S*\s*$|@/;
2222
const rxHexColor = /[0-9a-f]+\b|$|\s/yi;
2323
const rxMaybeProp1 = /^(prop(erty|\?)|atom|error|tag)/;
2424
const rxMaybeProp2 = /^(block|atBlock_parens|maybeprop)/;
@@ -79,7 +79,7 @@ async function helper(cm) {
7979
a < arr.length || ok && !(arr.length = ok);
8080
a++) {
8181
v = arr[a];
82-
if (v.text.indexOf(prevMatch) === v.i) {
82+
if ((v.text || v).indexOf(prevMatch) === v.i) {
8383
if (ok < a) arr[ok] = v;
8484
ok++;
8585
}
@@ -117,6 +117,8 @@ async function helper(cm) {
117117
(end = styles[i]) &&
118118
isSameToken(text, style, end)
119119
) i += 2;
120+
rxFilterable.lastIndex = prev;
121+
prev = Math.max(prev, text.search(rxFilterable));
120122
str = text.slice(prev, end);
121123
const left = text.slice(prev, ch).trim();
122124
const L = (leftLC = left.toLowerCase())[0];
@@ -229,32 +231,30 @@ async function helper(cm) {
229231
list.sort();
230232
}
231233
const len = leftLC.length;
232-
if (!leftLC || rxFilterable.test(leftLC)) {
233-
const names1 = new Map();
234-
const names2 = new Map();
235-
for (const v of list) {
236-
i = leftLC ? v.toLowerCase().indexOf(leftLC) : 0;
237-
if (i >= 0) (i ? names2 : names1).set(v, new Completion(i, v));
238-
}
239-
list = [...names1.values(), ...names2.values()];
240-
if (!prop) {
241-
const values1 = new Map();
242-
const values2 = new Map();
243-
if (!cssPropNames) await initCssProps();
244-
for (const name of cssPropNames) {
245-
i = 0;
246-
for (let a, b, v, lc = cssPropsLC[name];
247-
i >= 0 && (!leftLC || (i = lc.indexOf(leftLC, i)) >= 0);
248-
i = leftLC ? b : b + 1 || b/*retain -1 to end the loop*/
249-
) {
250-
a = leftLC ? lc.lastIndexOf('\n', i) + 1 : i;
251-
b = lc.indexOf('\n', i + len);
252-
v = cssProps[name].slice(a, b < 0 ? 1e9 : b);
253-
(i === a ? values1 : values2).set(name + v, new Completion(i - a, name, v));
254-
}
234+
const names1 = new Map();
235+
const names2 = new Map();
236+
for (const v of list) {
237+
i = leftLC ? v.toLowerCase().indexOf(leftLC) : 0;
238+
if (i >= 0) (i ? names2 : names1).set(v, new Completion(i, v));
239+
}
240+
list = [...names1.values(), ...names2.values()];
241+
if (!prop) {
242+
const values1 = new Map();
243+
const values2 = new Map();
244+
if (!cssPropNames) await initCssProps();
245+
for (const name of cssPropNames) {
246+
i = 0;
247+
for (let a, b, v, lc = cssPropsLC[name];
248+
i >= 0 && (!leftLC || (i = lc.indexOf(leftLC, i)) >= 0);
249+
i = leftLC ? b : b + 1 || b/*retain -1 to end the loop*/
250+
) {
251+
a = leftLC ? lc.lastIndexOf('\n', i) + 1 : i;
252+
b = lc.indexOf('\n', i + len);
253+
v = cssProps[name].slice(a, b < 0 ? 1e9 : b);
254+
(i === a ? values1 : values2).set(name + v, new Completion(i - a, name, v));
255255
}
256-
list.push(...values1.values(), ...values2.values());
257256
}
257+
list.push(...values1.values(), ...values2.values());
258258
}
259259
prev += Math.max(0, str.search(rxNonSpace));
260260
prevMatch = text.slice(prev, ch);

0 commit comments

Comments
 (0)