Skip to content

Commit 4cc200e

Browse files
committed
fix: use start range from instead of the current cursor position to find the matching tag
1 parent 8d8822c commit 4cc200e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@ define(function (require, exports, module) {
8888
// NOTE: we cannot get the end range from getPositionFromTagId
8989
// because on non-beautified code getPositionFromTagId may not provide correct end position
9090
const startRange = HTMLInstrumentation.getPositionFromTagId(editor, tagId);
91-
const endRange = CodeMirror.findMatchingTag(editor._codeMirror, editor.getCursorPos());
91+
if(!startRange) {
92+
return;
93+
}
9294

93-
if (!startRange || !endRange) {
95+
const endRange = CodeMirror.findMatchingTag(editor._codeMirror, startRange.from);
96+
if (!endRange) {
9497
return;
9598
}
99+
96100
const startPos = startRange.from;
97101
const endPos = endRange.close.to;
98102

@@ -144,11 +148,15 @@ define(function (require, exports, module) {
144148
// NOTE: we cannot get the end range from getPositionFromTagId
145149
// because on non-beautified code getPositionFromTagId may not provide correct end position
146150
const startRange = HTMLInstrumentation.getPositionFromTagId(editor, tagId);
147-
const endRange = CodeMirror.findMatchingTag(editor._codeMirror, editor.getCursorPos());
151+
if(!startRange) {
152+
return;
153+
}
148154

149-
if (!startRange || !endRange) {
155+
const endRange = CodeMirror.findMatchingTag(editor._codeMirror, startRange.from);
156+
if (!endRange) {
150157
return;
151158
}
159+
152160
const startPos = startRange.from;
153161
const endPos = endRange.close.to;
154162

0 commit comments

Comments
 (0)