diff --git a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/editor/diff/DiffEditorManager.kt b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/editor/diff/DiffEditorManager.kt index 7f645eec..1ba5e182 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/editor/diff/DiffEditorManager.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/editor/diff/DiffEditorManager.kt @@ -6,7 +6,6 @@ import com.intellij.diff.util.DiffUtil import com.intellij.diff.util.Side import com.intellij.openapi.application.runInEdt import com.intellij.openapi.diff.DiffBundle -import com.intellij.openapi.editor.Document import com.intellij.openapi.editor.LogicalPosition import com.intellij.openapi.editor.ScrollType import com.intellij.openapi.project.Project @@ -27,13 +26,14 @@ class DiffEditorManager( application.executeOnPooledThread { runInEdt { - ensureDocumentWritable(project, document) if (DiffUtil.executeWriteCommand(document, project, "Updating document") { document.setText( StringUtil.convertLineSeparators( currentText.replaceLast(searchContent.trim(), replaceContent.trim()) ) ) + + diffViewer.scheduleRediff() }) { diffViewer.rediff() scrollToLastChange(diffViewer) @@ -50,8 +50,6 @@ class DiffEditorManager( fun applyAllChanges(): List { val document = diffViewer.getDocument(Side.LEFT) - ensureDocumentWritable(project, document) - val allChanges = mutableListOf() while (true) { @@ -66,9 +64,7 @@ class DiffEditorManager( DiffBundle.message("message.replace.change.command") ) { diffViewer.replaceChange(change, Side.RIGHT) - runInEdt { - diffViewer.scheduleRediff() - } + diffViewer.scheduleRediff() } diffViewer.rediff(true) @@ -85,11 +81,4 @@ class DiffEditorManager( ScrollType.CENTER ) } - - private fun ensureDocumentWritable(project: Project, document: Document) { - if (!document.isWritable) { - DiffUtil.makeWritable(project, document) - document.setReadOnly(false) - } - } } \ No newline at end of file diff --git a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/parser/SseMessageParser.kt b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/parser/SseMessageParser.kt index 5b2d65b9..8d31433c 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/parser/SseMessageParser.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/parser/SseMessageParser.kt @@ -193,8 +193,6 @@ class SseMessageParser : MessageParser { } line.trim() == CODE_FENCE -> { - // Invalid search/replace block - missing REPLACE marker - // Mark done segments.add(CodeEnd("")) parserState = ParserState.Outside true @@ -212,7 +210,7 @@ class SseMessageParser : MessageParser { ) ) parserState = ParserState.InReplace(state.header, state.searchContent, newReplace) - false + true } } }