fix double apply on ai chat (#5671)

This commit is contained in:
centdix
2025-04-28 18:18:48 +02:00
committed by GitHub
parent e1ead53ce5
commit 775ef2ef6f
@@ -22,6 +22,7 @@ export class AIChatEditorHandler {
reviewingChanges: Writable<boolean> = writable(false)
groupChanges: { changes: VisualChangeWithDiffIndex[]; groupIndex: number }[] = []
pendingNewCode: string | undefined = undefined
constructor(editor: meditor.IStandaloneCodeEditor) {
this.editor = editor
@@ -29,6 +30,7 @@ export class AIChatEditorHandler {
clear() {
this.groupChanges = []
this.pendingNewCode = undefined
for (const collection of this.decorationsCollections) {
collection.clear()
}
@@ -166,6 +168,12 @@ export class AIChatEditorHandler {
}
async reviewAndApply(newCode: string) {
if (this.pendingNewCode === newCode) {
return
} else if (this.pendingNewCode) {
this.clear()
}
this.pendingNewCode = newCode
const changedLines = await this.calculateVisualChanges(newCode)
if (changedLines.length === 0) return