Skip to content

Commit

Permalink
fix creation file
Browse files Browse the repository at this point in the history
  • Loading branch information
reymondzzzz committed Oct 30, 2024
1 parent b16d2a9 commit e1a0117
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.intellij.execution.processTools.getResultStdoutStr
import com.intellij.ide.BrowserUtil
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.LogicalPosition
Expand Down Expand Up @@ -307,13 +308,12 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable {
private fun handleOpenFile(fileName: String, line: Int?) {
val sanitizedFileName = this.sanitizeFileNameForPosix(fileName)
val file = File(sanitizedFileName)
val vf = ApplicationManager.getApplication().runReadAction<VirtualFile?> {
VfsUtil.findFileByIoFile(file, true)
} ?: return

val fileDescriptor = OpenFileDescriptor(project, vf)

ApplicationManager.getApplication().invokeLater {
if (!file.exists()) {
file.createNewFile()
}
invokeLater {
val vf = VfsUtil.findFileByIoFile(file, true) ?: return@invokeLater
val fileDescriptor = OpenFileDescriptor(project, vf)
val editor = FileEditorManager.getInstance(project).openTextEditor(fileDescriptor, true)
line?.let {
editor?.caretModel?.moveToLogicalPosition(LogicalPosition(line, 0))
Expand Down

0 comments on commit e1a0117

Please sign in to comment.