Fix: use sticky flag to avoid text slicing

This commit is contained in:
eight 2017-11-09 13:50:03 +08:00
parent 53770c0db6
commit 6d411c01fc

View File

@ -374,33 +374,30 @@ function createAppliesToLineWidget(cm) {
function *findAppliesTo(posStart, posEnd) { function *findAppliesTo(posStart, posEnd) {
const text = cm.getValue(); const text = cm.getValue();
const re = /^[\t ]*@-moz-document\s+/mg; const re = /^[\t ]*@-moz-document\s+/mg;
const applyRe = /^(url|url-prefix|domain|regexp)\(((['"])(?:\\\\|\\\n|\\\3|[^\n])*?\3|[^)\n]*)\)[\s,]*/i; const applyRe = /(url|url-prefix|domain|regexp)\(((['"])(?:\\\\|\\\n|\\\3|[^\n])*?\3|[^)\n]*)\)[\s,]*/iyg;
let preIndex = re.lastIndex = posStart;
let match; let match;
let pos = cm.posFromIndex(preIndex); re.lastIndex = posStart;
while ((match = re.exec(text))) { while ((match = re.exec(text))) {
if (match.index >= posEnd) { if (match.index >= posEnd) {
return; return;
} }
pos = cm.findPosH(pos, match.index - preIndex, 'char');
const applies = []; const applies = [];
let t = text.slice(re.lastIndex);
let m; let m;
let offset = 0; applyRe.lastIndex = re.lastIndex;
while ((m = t.match(applyRe))) { while ((m = applyRe.exec(text))) {
const apply = createApply( const apply = createApply(
re.lastIndex + offset, m.index,
m[1], m[1],
unquote(m[2]), unquote(m[2]),
unquote(m[2]) !== m[2] unquote(m[2]) !== m[2]
); );
applies.push(apply); applies.push(apply);
t = t.slice(m[0].length); re.lastIndex = applyRe.lastIndex;
offset += m[0].length;
} }
yield {pos, applies}; yield {
preIndex = match.index; pos: cm.posFromIndex(match.index),
re.lastIndex = text.length - t.length; applies
};
} }
} }