Skip to content

Commit f4d3dc7

Browse files
dandeandeantjex
andauthored
Fix: LSP crash when editing code fences (#493)
Co-authored-by: Tillman Jex <[email protected]> Fixes issue 461: #461
1 parent f581447 commit f4d3dc7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/adapter/lsp/document.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,18 @@ var insideFenced = false
213213
var insideIndented = false
214214
var currentCodeBlockStart = -1
215215

216-
// check whether the current line in document is within a fenced or indented
216+
// check whether the current line in document is within a fenced or indented
217217
// code block
218218
func isLineWithinCodeBlock(lines []string, lineIndex int, line string) bool {
219-
// if line is already within code fences or indented code block
219+
// Reset global state from previous runs
220+
if lineIndex == 0 {
221+
insideInline = false
222+
insideFenced = false
223+
insideIndented = false
224+
currentCodeBlockStart = -1
225+
}
226+
227+
// if line is already within code fences or indented code block
220228
if insideFenced {
221229
if fencedEndRegex.FindStringIndex(line) != nil &&
222230
lines[currentCodeBlockStart][:3] == line[:3] {

0 commit comments

Comments
 (0)