diff --git a/markdown/core/src/main/kotlin/org/jetbrains/jewel/markdown/processing/MarkdownProcessor.kt b/markdown/core/src/main/kotlin/org/jetbrains/jewel/markdown/processing/MarkdownProcessor.kt index 7c39b704f..29da2539f 100644 --- a/markdown/core/src/main/kotlin/org/jetbrains/jewel/markdown/processing/MarkdownProcessor.kt +++ b/markdown/core/src/main/kotlin/org/jetbrains/jewel/markdown/processing/MarkdownProcessor.kt @@ -108,7 +108,7 @@ public class MarkdownProcessor( outerLoop@ for ((i, spans) in previousIndexes.withIndex()) { val (_, end) = spans for (j in currFirstLine..end) { - if (newLines[j] != previousLines[j]) { + if (j < 0 || j >= newLines.size || newLines[j] != previousLines[j]) { break@outerLoop } } @@ -125,7 +125,8 @@ public class MarkdownProcessor( outerLoop@ for ((i, spans) in previousIndexes.withIndex().reversed()) { val (begin, _) = spans for (j in begin until currLastLine) { - if (previousLines[j] != newLines[j + nLinesDelta]) { + val newIndex = j + nLinesDelta + if (newIndex < 0 || newIndex >= newLines.size || previousLines[j] != newLines[newIndex]) { break@outerLoop } } diff --git a/markdown/core/src/test/kotlin/org/jetbrains/jewel/markdown/processing/MarkdownProcessorTest.kt b/markdown/core/src/test/kotlin/org/jetbrains/jewel/markdown/processing/MarkdownProcessorTest.kt index 214c6b168..be147d3c0 100644 --- a/markdown/core/src/test/kotlin/org/jetbrains/jewel/markdown/processing/MarkdownProcessorTest.kt +++ b/markdown/core/src/test/kotlin/org/jetbrains/jewel/markdown/processing/MarkdownProcessorTest.kt @@ -15,6 +15,7 @@ import org.junit.Test private val rawMarkdown = """ Paragraph 0 + continue p0 # Header 1 Paragraph 2 * list item 3-1 @@ -32,8 +33,12 @@ private val rawMarkdown = """ Paragraph 7 Paragraph 8 + continue p8 """.trimIndent() +@Suppress( + "LargeClass", // Detekt triggers on files > 600 lines +) class MarkdownProcessorTest { private val htmlRenderer = HtmlRenderer.builder().build() @@ -45,6 +50,7 @@ class MarkdownProcessorTest { val secondRun = processor.processWithQuickEdits( """ Paragraph 0 + continue p0 # Header 1 Paragraph 2 @@ -57,7 +63,8 @@ class MarkdownProcessorTest { assertNotSame(firstRun[2], secondRun[2]) assertHtmlEquals( """ -

Paragraph 0

+

Paragraph 0 + continue p0

Header 1

Paragraph 2