Skip to content

Commit d85d802

Browse files
committed
refactor(code): rename HtmlLangSketch to HtmlHighlightSketch and update text param
- Renamed `HtmlLangSketch` to `HtmlHighlightSketch` for clarity. - Updated `text_` parameter to `allText` in `doneUpdateText` method for consistency. - Simplified `HtmlHighlightSketch` class and added documentation. - Cleaned up code formatting in `DiffStreamHandler`.
1 parent 58a7d07 commit d85d802

File tree

5 files changed

+46
-47
lines changed

5 files changed

+46
-47
lines changed

core/src/main/kotlin/cc/unitmesh/devti/diff/DiffStreamHandler.kt

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import com.intellij.openapi.editor.markup.RangeHighlighter
2424
import com.intellij.openapi.fileEditor.FileDocumentManager
2525
import com.intellij.openapi.fileEditor.FileEditorManager
2626
import com.intellij.openapi.fileEditor.TextEditor
27-
import com.intellij.openapi.fileTypes.PlainTextLanguage
2827
import com.intellij.openapi.project.Project
2928
import com.intellij.openapi.vfs.VirtualFile
3029
import cc.unitmesh.devti.diff.model.DiffLine
@@ -42,33 +41,35 @@ import kotlin.math.min
4241

4342
/**
4443
*
45-
* JButton("Apply Patch").apply {
44+
* ```kotlin
45+
* JButton("Apply Patch").apply {
4646
*
47-
* addActionListener {
48-
* val lookupFile =
49-
* project.lookupFile("src/main/java/com/phodal/shire/demo/service/BlogService.java")!!
50-
* val editor = FileEditorManager.getInstance(project).selectedTextEditor
51-
* val code = lookupFile.inputStream.bufferedReader().use { it.readText() }
47+
* addActionListener {
48+
* val lookupFile =
49+
* project.lookupFile("src/main/java/com/phodal/shire/demo/service/BlogService.java")!!
50+
* val editor = FileEditorManager.getInstance(project).selectedTextEditor
51+
* val code = lookupFile.inputStream.bufferedReader().use { it.readText() }
5252
*
53-
* val diffStreamHandler = DiffStreamHandler(
54-
* project,
55-
* editor = editor!!, 0, code.lines().size,
56-
* onClose = {
57-
* },
58-
* onFinish = {
59-
* ShirelangNotifications.info(project, "Patch Applied")
60-
* }
61-
* )
53+
* val diffStreamHandler = DiffStreamHandler(
54+
* project,
55+
* editor = editor!!, 0, code.lines().size,
56+
* onClose = {
57+
* },
58+
* onFinish = {
59+
* ShirelangNotifications.info(project, "Patch Applied")
60+
* }
61+
* )
6262
*
63-
* runInEdt {
64-
* diffStreamHandler
65-
* .streamDiffLinesToEditor(
66-
* code,
67-
* "使用为如下的代码添加删除功能,请使用 Markdown code 返回完整代码块: $code"
68-
* )
69-
* }
70-
* }
71-
* }
63+
* runInEdt {
64+
* diffStreamHandler
65+
* .streamDiffLinesToEditor(
66+
* code,
67+
* "使用为如下的代码添加删除功能,请使用 Markdown code 返回完整代码块: $code"
68+
* )
69+
* }
70+
* }
71+
* }
72+
* ```
7273
*/
7374
class DiffStreamHandler(
7475
private val project: Project,
@@ -198,9 +199,7 @@ class DiffStreamHandler(
198199
}
199200

200201
val highlighter = editor.markupModel.addLineHighlighter(
201-
unfinishedKey, min(
202-
i, editor.document.lineCount - 1
203-
), HighlighterLayer.LAST
202+
unfinishedKey, min(i, editor.document.lineCount - 1), HighlighterLayer.LAST
204203
)
205204
unfinishedHighlighters.add(highlighter)
206205
}

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/code/CodeHighlightSketch.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,25 @@ open class CodeHighlightSketch(
116116
}
117117
}
118118

119-
override fun doneUpdateText(text_: String) {
119+
override fun doneUpdateText(allText: String) {
120120
if (ideaLanguage?.displayName == "DevIn") {
121121
val parse = CodeFence.parse(editorFragment!!.editor.document.text)
122122
var panel: JComponent? = null
123123
when (parse.originLanguage) {
124124
"diff", "patch" -> {
125125
val langSketch = LanguageSketchProvider.provide("patch")?.create(project, parse.text) ?: return
126126
panel = langSketch.getComponent()
127-
langSketch.doneUpdateText(text_)
127+
langSketch.doneUpdateText(allText)
128128
}
129129
"html" -> {
130130
val langSketch = LanguageSketchProvider.provide("html")?.create(project, parse.text) ?: return
131131
panel = langSketch.getComponent()
132-
langSketch.doneUpdateText(text_)
132+
langSketch.doneUpdateText(allText)
133133
}
134134
"bash", "shell" -> {
135135
val langSketch = LanguageSketchProvider.provide("shell")?.create(project, parse.text) ?: return
136136
panel = langSketch.getComponent()
137-
langSketch.doneUpdateText(text_)
137+
langSketch.doneUpdateText(allText)
138138
}
139139
}
140140

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cc.unitmesh.devti.sketch.ui.code
2+
3+
import cc.unitmesh.devti.sketch.ui.ExtensionLangSketch
4+
import com.intellij.lang.html.HTMLLanguage
5+
import com.intellij.openapi.project.Project
6+
7+
/**
8+
* Before WebView rendering, we use this class to highlight the HTML code.
9+
*/
10+
class HtmlHighlightSketch(override val project: Project, override val text: String) :
11+
CodeHighlightSketch(project, text, HTMLLanguage.INSTANCE), ExtensionLangSketch {
12+
override fun getExtensionName(): String = "HTML"
13+
}

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/code/HtmlLangSketch.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/webview/WebpageSketchProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package cc.unitmesh.devti.sketch.ui.webview
22

33
import cc.unitmesh.devti.sketch.ui.ExtensionLangSketch
44
import cc.unitmesh.devti.sketch.ui.LanguageSketchProvider
5-
import cc.unitmesh.devti.sketch.ui.code.HtmlLangSketch
5+
import cc.unitmesh.devti.sketch.ui.code.HtmlHighlightSketch
66
import com.intellij.openapi.project.Project
77

88
class WebpageSketchProvider : LanguageSketchProvider {
@@ -15,7 +15,7 @@ class WebpageSketchProvider : LanguageSketchProvider {
1515
return WebpageLangSketch(project, content)
1616
}
1717

18-
return HtmlLangSketch(project, content)
18+
return HtmlHighlightSketch(project, content)
1919
}
2020
}
2121

0 commit comments

Comments
 (0)