@@ -22,6 +22,7 @@ import com.intellij.openapi.command.WriteCommandAction
22
22
import com.intellij.openapi.diagnostic.logger
23
23
import com.intellij.openapi.editor.Document
24
24
import com.intellij.openapi.editor.EditorFactory
25
+ import com.intellij.openapi.editor.ex.EditorEx
25
26
import com.intellij.openapi.fileEditor.FileDocumentManager
26
27
import com.intellij.openapi.fileEditor.FileEditor
27
28
import com.intellij.openapi.fileTypes.PlainTextLanguage
@@ -86,6 +87,11 @@ open class CodeHighlightSketch(
86
87
fun initEditor (text : String , fileName : String? = null) {
87
88
if (hasSetupAction) return
88
89
hasSetupAction = true
90
+
91
+ if (isUser) {
92
+ setupSimpleEditor(text, fileName)
93
+ return
94
+ }
89
95
90
96
val editor = EditorUtil .createCodeViewerEditor(project, text, ideaLanguage, fileName, this )
91
97
@@ -102,24 +108,49 @@ open class CodeHighlightSketch(
102
108
editorFragment = EditorFragment (editor, minDevinLineThreshold, previewEditor)
103
109
setupDevInsView(text)
104
110
} else {
105
- editorFragment = EditorFragment (editor, editorLineThreshold, previewEditor)
106
- add(editorFragment!! .getContent())
111
+ setupRegularEditor(editor)
107
112
}
108
113
114
+ setupToolbarAndStyling(fileName, editor)
115
+ }
116
+
117
+ private fun setupSimpleEditor (text : String , fileName : String? ) {
118
+ val editor = EditorUtil .createCodeViewerEditor(project, text, ideaLanguage, fileName, this )
119
+
120
+ border = if (withLeftRightBorder) {
121
+ JBEmptyBorder (4 , 4 , 4 , 4 )
122
+ } else {
123
+ JBEmptyBorder (4 , 0 , 0 , 0 )
124
+ }
125
+
126
+ editor.component.isOpaque = true
127
+ editorFragment = EditorFragment (editor, editorLineThreshold, previewEditor)
128
+ add(editorFragment!! .getContent())
129
+
130
+ setupToolbarAndStyling(fileName, editor)
131
+ }
132
+
133
+ private fun setupRegularEditor (editor : EditorEx ) {
134
+ editorFragment = EditorFragment (editor, editorLineThreshold, previewEditor)
135
+ add(editorFragment!! .getContent())
136
+ }
137
+
138
+ private fun setupToolbarAndStyling (fileName : String? , editor : EditorEx ) {
109
139
val isDeclarePackageFile = BuildSystemProvider .isDeclarePackageFile(fileName)
110
140
val lowercase = textLanguage?.lowercase()
141
+
111
142
if (textLanguage != null && lowercase != " markdown" && lowercase != " plain text" ) {
112
- if (showToolbar && ! isDevIns ) {
143
+ if (showToolbar && lowercase != " devin " ) {
113
144
toolbar = setupActionBar(project, editor, isDeclarePackageFile)
114
145
}
115
146
} else {
116
147
editorFragment?.editor?.backgroundColor = JBColor .PanelBackground
117
148
}
118
149
119
- if (lowercase == " devin " ) {
120
- editorFragment?.editor?.setBorder(JBEmptyBorder (1 , 1 , 0 , 1 ))
121
- } else if (lowercase != " markdown" ) {
122
- editorFragment?.editor?.setBorder(JBEmptyBorder (1 , 0 , 0 , 0 ))
150
+ when (lowercase) {
151
+ " devin " -> editorFragment?.editor?.setBorder(JBEmptyBorder (1 , 1 , 0 , 1 ))
152
+ " markdown" -> { /* no border changes needed */ }
153
+ else -> editorFragment?.editor?.setBorder(JBEmptyBorder (1 , 0 , 0 , 0 ))
123
154
}
124
155
}
125
156
@@ -244,6 +275,7 @@ open class CodeHighlightSketch(
244
275
override fun updateViewText (text : String , complete : Boolean ) {
245
276
isComplete = complete
246
277
278
+ // Initialize editor if not already done and text is not empty
247
279
if (! hasSetupAction && text.trim().isNotEmpty()) {
248
280
initEditor(text)
249
281
}
@@ -256,6 +288,7 @@ open class CodeHighlightSketch(
256
288
try {
257
289
document?.replaceString(0 , document.textLength, normalizedText)
258
290
291
+ // Update DevIns collapsed panel preview text if applicable
259
292
if (isDevIns && devInsCollapsedPanel != null ) {
260
293
val firstLine = normalizedText.lines().firstOrNull() ? : " "
261
294
val components = devInsCollapsedPanel!! .components
@@ -273,24 +306,24 @@ open class CodeHighlightSketch(
273
306
logger<CodeHighlightSketch >().error(" Error updating editor text" , e)
274
307
}
275
308
276
- // 更新 runButton 图标状态
309
+ // Update run button icon state for DevIns
277
310
updateRunButtonIcon()
278
311
279
312
val lineCount = document?.lineCount ? : 0
280
313
if (lineCount > editorLineThreshold) {
281
314
editorFragment?.updateExpandCollapseLabel()
282
315
}
283
-
284
- if (complete && isDevIns) {
285
- if (! isCollapsed) {
286
- toggleEditorVisibility()
287
- }
316
+
317
+ // Auto-collapse DevIns view when complete
318
+ if (complete && isDevIns && ! isCollapsed) {
319
+ toggleEditorVisibility()
288
320
}
289
321
}
290
322
}
291
323
292
324
override fun onDoneStream (allText : String ) {
293
- if (ideaLanguage?.displayName != " DevIn" ) return
325
+ // Only process DevIns commands for non-user messages
326
+ if (isUser || ideaLanguage?.displayName != " DevIn" ) return
294
327
295
328
val currentText = getViewText()
296
329
if (currentText.startsWith(" /" + BuiltinCommand .WRITE .commandName + " :" )) {
0 commit comments