Add: offset info

This commit is contained in:
eight 2017-09-15 15:36:44 +08:00
parent ccb5f488e5
commit 693a0483e3

View File

@ -292,9 +292,29 @@ function createSourceEditor(style) {
const applies = []; const applies = [];
let t = text.slice(re.lastIndex); let t = text.slice(re.lastIndex);
let m; let m;
let offset = 0;
while ((m = t.match(applyRe))) { while ((m = t.match(applyRe))) {
applies.push({type: m[1], value: normalizeString(m[2])}); const apply = {
type: m[1],
value: normalizeString(m[2]),
typeStart: null,
typeEnd: null,
valueStart: null,
valueEnd: null,
};
apply.typeStart = re.lastIndex + offset;
apply.typeEnd = apply.typeStart + apply.type.length;
apply.valueStart = apply.typeEnd + (apply.value === m[2] ? 1 : 2);
apply.valueEnd = apply.valueStart + apply.value.length;
applies.push({
typeStart: re.lastIndex + offset;
typeEnd: re.lastIndex + offset + m[1].length
type: m[1],
valueStart:
value: value,
});
t = t.slice(m[0].length); t = t.slice(m[0].length);
offset += m[0].length;
} }
yield {pos, applies}; yield {pos, applies};
preIndex = match.index; preIndex = match.index;