fix: Clear all diff blocks before streaming and ensure dispose is run on EDT

- Clear all diff blocks before running the diff stream.
- Ensure that inlay executes dispose on the Event Dispatch Thread (EDT).
This commit is contained in:
liuk 2025-01-04 19:38:39 +08:00
parent aa02e0bd63
commit 41357cd00c
2 changed files with 14 additions and 2 deletions

View file

@ -469,6 +469,10 @@ class IdeProtocolClient(
}
val diffStreamService = project.service<DiffStreamService>()
// Clear all diff blocks before running the diff stream
diffStreamService.reject(editor)
val llmTitle = (llm as? Map<*, *>)?.get("title") as? String ?: ""
val prompt =
@ -501,7 +505,6 @@ class IdeProtocolClient(
rif?.range?.end?.line ?: (editor.document.lineCount - 1),
{}, {})
val diffStreamService = project.service<DiffStreamService>()
diffStreamService.register(diffStreamHandler, editor)
diffStreamHandler.streamDiffLinesToEditor(

View file

@ -3,6 +3,7 @@ package com.github.continuedev.continueintellijextension.editor
import com.github.continuedev.continueintellijextension.utils.getAltKeyLabel
import com.github.continuedev.continueintellijextension.utils.getShiftKeyLabel
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
@ -11,6 +12,7 @@ import com.intellij.openapi.editor.markup.HighlighterLayer
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.ui.JBColor
import com.intellij.util.application
import java.awt.*
import javax.swing.BorderFactory
import javax.swing.JButton
@ -41,7 +43,14 @@ class VerticalDiffBlock(
}
fun clearEditorUI() {
deletionInlay?.dispose()
deletionInlay?.let {
// Ensure that dispose is executed on EDT
if (application.isDispatchThread) {
it.dispose()
} else {
invokeLater { it.dispose() }
}
}
removeGreenHighlighters()
removeButtons()
}