diff --git a/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/SharedChatPane.kt b/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/SharedChatPane.kt index c8f90452..c159299a 100644 --- a/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/SharedChatPane.kt +++ b/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/SharedChatPane.kt @@ -329,7 +329,7 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable { private fun deleteFile(fileName: String) { logger.warn("deleteFile: $fileName") - ApplicationManager.getApplication().runReadAction { + ApplicationManager.getApplication().invokeLater { LocalFileSystem.getInstance().findFileByPath(fileName)?.delete(this.project) } } @@ -363,15 +363,13 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable { private fun setContent(fileName: String, content: String) { logger.warn("setContent: item.fileNameEdit = $fileName") - val file = ApplicationManager.getApplication().runReadAction { - LocalFileSystem.getInstance().refreshAndFindFileByPath(fileName) - } - if (file == null) { - logger.warn("setContent: item.fileNameEdit = $fileName is null") - return - } - ApplicationManager.getApplication().invokeLater { + val file = LocalFileSystem.getInstance().refreshAndFindFileByPath(fileName) + if (file == null) { + logger.warn("setContent: item.fileNameEdit = $fileName is null") + return@invokeLater + } + FileDocumentManager.getInstance().getDocument(file)?.setText(content) } } @@ -403,16 +401,14 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable { logger.warn("showPatch: item.fileNameEdit = $fileName") this.handleAnimationStop(fileName) - val file = ApplicationManager.getApplication().runReadAction { - LocalFileSystem.getInstance().refreshAndFindFileByPath(fileName) - } - if (file == null) { - logger.warn("showPatch: item.fileNameEdit = $fileName is null") - return - } - - val fileDescriptor = OpenFileDescriptor(project, file) ApplicationManager.getApplication().invokeLater { + val file = LocalFileSystem.getInstance().refreshAndFindFileByPath(fileName) + if (file == null) { + logger.warn("showPatch: item.fileNameEdit = $fileName is null") + return@invokeLater + } + + val fileDescriptor = OpenFileDescriptor(project, file) val editor = FileEditorManager.getInstance(project).openTextEditor(fileDescriptor, true) editor?.selectionModel?.setSelection(0, editor.document.textLength) if (editor != null) {