From 775ef2ef6fc51ab1cc74b69cea596460600bc002 Mon Sep 17 00:00:00 2001 From: centdix <40307056+centdix@users.noreply.github.com> Date: Mon, 28 Apr 2025 18:18:48 +0200 Subject: [PATCH] fix double apply on ai chat (#5671) --- .../src/lib/components/copilot/chat/monaco-adapter.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/lib/components/copilot/chat/monaco-adapter.ts b/frontend/src/lib/components/copilot/chat/monaco-adapter.ts index f14b832eb2..a8168fdba2 100644 --- a/frontend/src/lib/components/copilot/chat/monaco-adapter.ts +++ b/frontend/src/lib/components/copilot/chat/monaco-adapter.ts @@ -22,6 +22,7 @@ export class AIChatEditorHandler { reviewingChanges: Writable = 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