From 693a0483e369c70cbab90f7e69c6deaf96f8d0f6 Mon Sep 17 00:00:00 2001 From: eight Date: Fri, 15 Sep 2017 15:36:44 +0800 Subject: [PATCH] Add: offset info --- edit/source-editor.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/edit/source-editor.js b/edit/source-editor.js index 9291bdce..adc08997 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -292,9 +292,29 @@ function createSourceEditor(style) { const applies = []; let t = text.slice(re.lastIndex); let m; + let offset = 0; 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); + offset += m[0].length; } yield {pos, applies}; preIndex = match.index;