Skip to content

Commit 84f0988

Browse files
committed
fix: highlighting problems
1 parent 213c69d commit 84f0988

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/main/kotlin/com/github/xepozz/php_dump/panel/OpcodesTerminalPanel.kt

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
2121
import com.intellij.openapi.fileEditor.FileEditorManager
2222
import com.intellij.openapi.project.Project
2323
import com.intellij.openapi.ui.SimpleToolWindowPanel
24+
import com.intellij.psi.PsiDocumentManager
25+
import com.intellij.psi.PsiManager
26+
import com.intellij.testFramework.LightVirtualFile
2427
import com.jetbrains.php.lang.PhpFileType
2528
import kotlinx.coroutines.CoroutineScope
2629
import kotlinx.coroutines.Dispatchers
@@ -34,16 +37,30 @@ import javax.swing.JPanel
3437
class OpcodesTerminalPanel(
3538
val project: Project,
3639
) : SimpleToolWindowPanel(false, false), RefreshablePanel, Disposable {
40+
val fileEditorManager = FileEditorManager.getInstance(project)
41+
3742
private val service = project.getService(OpcodesDumperService::class.java)
3843
private val state = PhpDumpSettingsService.getInstance(project)
3944
private val editorFactory: EditorFactory = EditorFactory.getInstance()
40-
private val document = editorFactory.createDocument("")
41-
private val editor = editorFactory.createEditor(document, project, PHPOpFileType.INSTANCE, false) as EditorEx
45+
46+
private val virtualFile: LightVirtualFile = LightVirtualFile(
47+
"opcodes.phpop",
48+
PHPOpFileType.INSTANCE,
49+
""
50+
)
51+
val psiFile = PsiManager.getInstance(project).findFile(virtualFile)!!
52+
val document = PsiDocumentManager.getInstance(project).getDocument(psiFile)!!
53+
54+
private var editor = editorFactory.createEditor(
55+
document,
56+
project,
57+
virtualFile,
58+
false
59+
) as EditorEx
4260
val viewComponent = editor.component
4361

4462
init {
4563
configureEditor()
46-
4764
createToolBar()
4865
createContent()
4966
}
@@ -67,9 +84,7 @@ class OpcodesTerminalPanel(
6784
add(RefreshAction { refresh(project, RefreshType.MANUAL) })
6885
add(object : AnAction("Clear Output", "Clear the output", AllIcons.Actions.GC) {
6986
override fun actionPerformed(e: AnActionEvent) {
70-
WriteCommandAction.runWriteCommandAction(project) {
71-
document.setText("")
72-
}
87+
setDocumentText(project, "")
7388
}
7489

7590
override fun getActionUpdateThread() = ActionUpdateThread.EDT
@@ -171,22 +186,26 @@ class OpcodesTerminalPanel(
171186
if (type == RefreshType.AUTO && !state.autoRefresh) {
172187
return
173188
}
174-
val editor = FileEditorManager.getInstance(project).selectedTextEditor ?: return
189+
val editor = fileEditorManager.selectedTextEditor ?: return
175190
val virtualFile = editor.virtualFile ?: return
176191

177192
CoroutineScope(Dispatchers.IO).launch {
178193
val result = service.dump(virtualFile)
179194

180195
val content = result as? String ?: "No output"
181196

182-
WriteCommandAction.runWriteCommandAction(project) {
183-
document.setText(content)
184-
}
197+
setDocumentText(project, content)
198+
}
199+
}
200+
201+
private fun setDocumentText(project: Project, content: String) {
202+
WriteCommandAction.runWriteCommandAction(project) {
203+
document.setText(content)
204+
PsiDocumentManager.getInstance(project).commitDocument(document)
185205
}
186206
}
187207

188208
override fun dispose() {
189209
editorFactory.releaseEditor(editor)
190210
}
191-
}
192-
211+
}

0 commit comments

Comments
 (0)