generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(code): extract MarkdownViewer for reusable component
Introduce MarkdownViewer to centralize the creation of JEditorPane for markdown rendering. Replace redundant createBaseComponent implementations in TextBlockView with calls to MarkdownViewer.createBaseComponent. Clean up related code and imports.
- Loading branch information
Showing
5 changed files
with
45 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
core/src/main/kotlin/cc/unitmesh/devti/gui/chat/view/MessageView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/code/MarkdownViewer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cc.unitmesh.devti.sketch.ui.code | ||
|
||
import com.intellij.openapi.util.text.StringUtil | ||
import com.intellij.temporary.gui.block.LineSpacingExtension | ||
import com.intellij.util.ui.HTMLEditorKitBuilder | ||
import javax.swing.JEditorPane | ||
import javax.swing.text.DefaultCaret | ||
|
||
object MarkdownViewer { | ||
fun createBaseComponent(): JEditorPane { | ||
val jEditorPane = JEditorPane() | ||
jEditorPane.setContentType("text/html") | ||
val htmlEditorKit = HTMLEditorKitBuilder() | ||
.withViewFactoryExtensions( | ||
LineSpacingExtension(0.2f) | ||
).build() | ||
|
||
htmlEditorKit.getStyleSheet().addRule("p {margin-top: 1px}") | ||
|
||
jEditorPane.also { | ||
it.editorKit = htmlEditorKit | ||
it.isEditable = false | ||
it.putClientProperty("JEditorPane.honorDisplayProperties", true) | ||
it.isOpaque = false | ||
it.border = null | ||
it.putClientProperty( | ||
"AccessibleName", | ||
StringUtil.unescapeXmlEntities(StringUtil.stripHtml("", " ")) | ||
) | ||
it.text = "" | ||
} | ||
|
||
if (jEditorPane.caret != null) { | ||
jEditorPane.setCaretPosition(0) | ||
(jEditorPane.caret as? DefaultCaret)?.updatePolicy = 1 | ||
} | ||
|
||
return jEditorPane | ||
} | ||
|
||
} |