Skip to content

Commit c07eee8

Browse files
committed
feat(editor): add preview editor support to EditorFragment
Introduced optional `previewEditor` parameter to `EditorFragment` to support preview editors. Updated related code to handle preview editor components when available.
1 parent 4d0b823 commit c07eee8

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchToolWindow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class SketchToolWindow(val project: Project, val editor: Editor?, private val sh
217217

218218
fun addRequestPrompt(text: String) {
219219
runInEdt {
220-
historyPanel.add(createSingleTextView(text, language = "Markdown"))
220+
historyPanel.add(createSingleTextView(text, language = "DevIn"))
221221
this.revalidate()
222222
this.repaint()
223223
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ import com.intellij.util.ui.JBUI
3131
import cc.unitmesh.devti.sketch.ui.LangSketch
3232
import cc.unitmesh.devti.sketch.ui.LanguageSketchProvider
3333
import com.intellij.ide.scratch.ScratchRootType
34+
import com.intellij.openapi.fileEditor.FileEditor
3435
import com.intellij.openapi.fileEditor.FileEditorProvider
3536
import com.intellij.openapi.fileEditor.TextEditorWithPreview
36-
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
3737
import com.intellij.openapi.util.text.StringUtil
3838
import com.intellij.psi.PsiManager
3939
import com.intellij.temporary.gui.block.whenDisposed
4040
import com.intellij.util.ui.JBEmptyBorder
41-
import org.intellij.plugins.markdown.lang.MarkdownLanguage
42-
import org.intellij.plugins.markdown.ui.preview.MarkdownEditorWithPreview
4341
import java.awt.BorderLayout
4442
import javax.swing.BoxLayout
4543
import javax.swing.JButton
@@ -59,6 +57,7 @@ open class CodeHighlightSketch(
5957
private var textLanguage: String? = null
6058

6159
var editorFragment: EditorFragment? = null
60+
var previewEditor: FileEditor? = null
6261
private var hasSetupAction = false
6362

6463
init {
@@ -88,9 +87,9 @@ open class CodeHighlightSketch(
8887

8988
if (ideaLanguage?.displayName == "DevIn") {
9089
isDevIns = true
91-
editorFragment = EditorFragment(editor, devinLineThreshold)
90+
editorFragment = EditorFragment(editor, devinLineThreshold, previewEditor)
9291
} else {
93-
editorFragment = EditorFragment(editor, editorLineThreshold)
92+
editorFragment = EditorFragment(editor, editorLineThreshold, previewEditor)
9493
}
9594

9695
add(editorFragment!!.getContent(), BorderLayout.CENTER)
@@ -114,6 +113,9 @@ open class CodeHighlightSketch(
114113
val preview = createEditor as? TextEditorWithPreview ?: return null
115114
var editor = preview?.editor as? EditorEx ?: return null
116115
configEditor(editor, project, file, false)
116+
// previewEditor = preview.previewEditor
117+
// previewEditor?.component?.isOpaque = true
118+
// previewEditor?.component?.minimumSize = JBUI.size(0, 0)
117119
return editor
118120
}
119121

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.intellij.openapi.editor.Editor
55
import com.intellij.openapi.editor.event.CaretEvent
66
import com.intellij.openapi.editor.event.CaretListener
77
import com.intellij.openapi.editor.ex.EditorEx
8+
import com.intellij.openapi.fileEditor.FileEditor
89
import com.intellij.ui.components.JBLabel
910
import com.intellij.util.ui.JBUI
1011
import com.intellij.util.ui.components.BorderLayoutPanel
@@ -31,7 +32,11 @@ class EditorPadding(private val editor: Editor, pad: Int) :
3132
}
3233

3334

34-
class EditorFragment(var editor: EditorEx, private val editorLineThreshold: Int = EDITOR_LINE_THRESHOLD) {
35+
class EditorFragment(
36+
var editor: EditorEx,
37+
private val editorLineThreshold: Int = EDITOR_LINE_THRESHOLD,
38+
private val previewEditor: FileEditor?
39+
) {
3540
private val expandCollapseTextLabel: JBLabel = JBLabel("", 0).apply {
3641
isOpaque = true
3742
isVisible = false
@@ -54,7 +59,11 @@ class EditorFragment(var editor: EditorEx, private val editorLineThreshold: Int
5459
}
5560
}.apply {
5661
isOpaque = true
57-
addToCenter(editor.component)
62+
if (previewEditor != null) {
63+
addToCenter(previewEditor.component)
64+
} else {
65+
addToCenter(editor.component)
66+
}
5867
addToBottom(expandCollapseTextLabel)
5968
}
6069
}

0 commit comments

Comments
 (0)