Skip to content

Commit 558be04

Browse files
committed
refactor(CodeBlockView): replace content with graphProperty
Replace direct string content with GraphProperty<String> in createCodeViewer to enable observable properties. This change allows for dynamic updates to the code content.
1 parent 0c82a15 commit 558be04

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

core/src/main/kotlin/com/intellij/temporary/gui/block/CodeBlockView.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import com.intellij.openapi.editor.ex.FocusChangeListener
2222
import com.intellij.openapi.editor.ex.MarkupModelEx
2323
import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory
2424
import com.intellij.openapi.fileEditor.FileDocumentManager
25+
import com.intellij.openapi.observable.properties.GraphProperty
26+
import com.intellij.openapi.observable.properties.PropertyGraph
2527
import com.intellij.openapi.project.Project
2628
import com.intellij.openapi.util.Disposer
2729
import com.intellij.openapi.vfs.VirtualFile
@@ -69,8 +71,9 @@ class CodeBlockView(
6971
private fun updateOrCreateCodeView(): CodePartEditorInfo? {
7072
val code: CodeFence = getBlock().code
7173
if (editorInfo == null) {
74+
val graphProperty = PropertyGraph(null, false).property(code.text)
7275
val editorInfo: CodePartEditorInfo = createCodeViewer(
73-
project, code.text, disposable, code.language, getBlock().getMessage()
76+
project, graphProperty, disposable, code.language, getBlock().getMessage()
7477
)
7578
this.editorInfo = editorInfo
7679
} else {
@@ -142,7 +145,7 @@ class CodeBlockView(
142145

143146
fun createCodeViewer(
144147
project: Project,
145-
content: String,
148+
graphProperty: GraphProperty<String>,
146149
disposable: Disposable,
147150
language: Language,
148151
message: CompletableMessage,
@@ -151,7 +154,7 @@ class CodeBlockView(
151154

152155
val ext = CodeFence.lookupFileExt(language.displayName)
153156
val fileTimeSuffix = System.currentTimeMillis()
154-
val file = LightVirtualFile("autodev-${fileTimeSuffix}.${ext}", language, content)
157+
val file = LightVirtualFile("autodev-${fileTimeSuffix}.${ext}", language, graphProperty.get())
155158

156159
val document: Document =
157160
file.findDocument() ?: throw IllegalStateException("Document not found")

0 commit comments

Comments
 (0)