From d9c4c0f649267392062e9573c2d3894e5071995d Mon Sep 17 00:00:00 2001 From: Gmaker689 <1711322114@qq.com> Date: Thu, 18 Jun 2026 21:05:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Diff=E6=89=93=E5=BC=80=E5=90=8E=E7=AB=8B?= =?UTF-8?q?=E5=8D=B3=E8=A7=A6=E5=8F=91=E7=8A=B6=E6=80=81=E6=A0=8F=E5=88=B7?= =?UTF-8?q?=E6=96=B0=20+=20=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E5=8F=AA?= =?UTF-8?q?=E5=9C=A8Accept/Reject=E6=97=B6=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - showFileDiff/showEditDiff 末尾调用 onDiffAction 通知状态栏切换 Diff 模式 - deleteSessionFiles 独立方法,只在 Accept/Reject 时调用 - clearSession 仅清除会话状态,不删文件(手动关 Diff 后可重新打开) --- src/render/diffViewer.ts | 41 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/render/diffViewer.ts b/src/render/diffViewer.ts index 8180769..8e07ed8 100644 --- a/src/render/diffViewer.ts +++ b/src/render/diffViewer.ts @@ -3,8 +3,9 @@ * * 关键: * 1. 临时文件(非 untitled)避免保存提示 - * 2. Accept/Reject 后自动推进到下一个 pending 文件 - * 3. 状态栏按钮在 Diff 模式下可见 + * 2. ★ 临时文件只在 Accept/Reject 后删除,手动关闭 Diff 不影响 + * 3. Accept/Reject 后自动推进到下一个 pending 文件 + * 4. 状态栏按钮在 Diff 模式下可见 */ import * as vscode from 'vscode'; @@ -63,6 +64,9 @@ export class DiffViewer { this.activeSession!.afterUri, `${fileName} — AI ${toolLabel} #${editRecord.id.slice(0, 6)} · 状态栏操作` ); + + // ★ 通知外部刷新状态栏(切换到 Diff 模式显示 Accept/Reject 按钮) + this.onDiffAction?.(); } async showFileDiff(fileChange: FileChange): Promise { @@ -86,6 +90,9 @@ export class DiffViewer { this.activeSession!.afterUri, `${fileName} — ${fileChange.edits.length} 次 AI 编辑 · 状态栏操作` ); + + // ★ 通知外部刷新状态栏(切换到 Diff 模式显示 Accept/Reject 按钮) + this.onDiffAction?.(); } async showCurrentFileDiff(): Promise { @@ -103,6 +110,8 @@ export class DiffViewer { // ---- Diff 界面操作 (Bug 1 修复: 自动推进) ---- + // ★ Accept/Reject 后删除临时文件 + 关闭 Diff + async acceptCurrentDiff(): Promise { if (!this.activeSession) return; const { fileId, editId } = this.activeSession; @@ -114,10 +123,9 @@ export class DiffViewer { } vscode.window.showInformationMessage('AI Diff: 已接受 ✓'); + this.deleteSessionFiles(); // ★ Accept 后才删 await this.closeDiff(); this.onDiffAction?.(); - - // ★ Bug 1 修复: 自动推进到下一个待处理文件 this.advanceToNext(fileId); } @@ -132,14 +140,12 @@ export class DiffViewer { } vscode.window.showInformationMessage('AI Diff: 已拒绝 ✗'); + this.deleteSessionFiles(); // ★ Reject 后才删 await this.closeDiff(); this.onDiffAction?.(); - - // ★ Bug 1 修复: 自动推进 this.advanceToNext(fileId); } - /** ★ 接受当前文件的所有编辑 (Diff 界面 Accept All) */ async acceptAllFromDiff(): Promise { if (!this.activeSession) return; const { fileId } = this.activeSession; @@ -147,6 +153,7 @@ export class DiffViewer { if (ok) { vscode.window.showInformationMessage('AI Diff: 已接受此文件全部 ✓'); } + this.deleteSessionFiles(); // ★ AcceptAll 后才删 await this.closeDiff(); this.onDiffAction?.(); this.advanceToNext(fileId); @@ -209,15 +216,19 @@ export class DiffViewer { }); } + /** ★ 删除当前会话的临时文件(只在 Accept/Reject 时调用) */ + private deleteSessionFiles(): void { + if (!this.activeSession) return; + [this.activeSession.beforeTmpPath, this.activeSession.afterTmpPath].forEach(p => { + try { if (fs.existsSync(p)) fs.unlinkSync(p); } catch { /* ok */ } + }); + this.tmpFiles = this.tmpFiles.filter( + f => f !== this.activeSession!.beforeTmpPath && f !== this.activeSession!.afterTmpPath + ); + } + + /** 清除会话状态(不删文件!手动关闭 Diff 后不影响重新打开) */ private clearSession(): void { - if (this.activeSession) { - [this.activeSession.beforeTmpPath, this.activeSession.afterTmpPath].forEach(p => { - try { if (fs.existsSync(p)) fs.unlinkSync(p); } catch { /* ok */ } - }); - this.tmpFiles = this.tmpFiles.filter( - f => f !== this.activeSession!.beforeTmpPath && f !== this.activeSession!.afterTmpPath - ); - } this.activeSession = null; if (this.closeListener) { this.closeListener.dispose(); this.closeListener = null; } }