From 6340eac498ed4b22dfb15cdb8b4b218397bafd2d Mon Sep 17 00:00:00 2001 From: Louis Vignier Date: Tue, 25 Apr 2023 18:04:55 +0200 Subject: [PATCH] [codeInspection.ui] Fix
 parsing in
 DescriptionEditorPane

IJ-CR-106458

GitOrigin-RevId: 6abb696717e5198d4b2bab258066aa7657579b8b
---
 .../profile/codeInspection/ui/DescriptionEditorPane.kt     | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/DescriptionEditorPane.kt b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/DescriptionEditorPane.kt
index 7e6487532f13..236b97352fcd 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/DescriptionEditorPane.kt
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/DescriptionEditorPane.kt
@@ -19,7 +19,6 @@ import java.awt.Color
 import java.awt.Point
 import java.io.IOException
 import java.io.StringReader
-import java.lang.IllegalStateException
 import javax.swing.JEditorPane
 import javax.swing.text.html.HTMLEditorKit
 
@@ -75,7 +74,11 @@ fun JEditorPane.readHTMLWithCodeHighlighting(text: String, language: String?) {
     val psiFileFactory = PsiFileFactory.getInstance(defaultProject)
 
     val defaultFile = psiFileFactory.createFileFromText(PlainTextLanguage.INSTANCE, "")
-    val content = codeSnippet.text().let { it.substringBefore("\n") + "\n" + it.substringAfter("\n").trimIndent() }
+    val content = codeSnippet.text().let { text ->
+      val beforeFirstNewline = text.substringBefore("\n")
+      val afterFirstNewline = text.substringAfter("\n", "").trimIndent()
+      if (afterFirstNewline.isEmpty()) beforeFirstNewline else "$beforeFirstNewline\n$afterFirstNewline"
+    }
       .trimEnd()
       .replaceIndent("  ")
     var snippet: String