mirror of
https://github.com/Gmaker689/ai-diff-preview.git
synced 2026-09-26 23:11:51 +08:00
fix: Diff打开后立即触发状态栏刷新 + 临时文件只在Accept/Reject时删除
- showFileDiff/showEditDiff 末尾调用 onDiffAction 通知状态栏切换 Diff 模式 - deleteSessionFiles 独立方法,只在 Accept/Reject 时调用 - clearSession 仅清除会话状态,不删文件(手动关 Diff 后可重新打开)
This commit is contained in:
+26
-15
@@ -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<void> {
|
||||
@@ -86,6 +90,9 @@ export class DiffViewer {
|
||||
this.activeSession!.afterUri,
|
||||
`${fileName} — ${fileChange.edits.length} 次 AI 编辑 · 状态栏操作`
|
||||
);
|
||||
|
||||
// ★ 通知外部刷新状态栏(切换到 Diff 模式显示 Accept/Reject 按钮)
|
||||
this.onDiffAction?.();
|
||||
}
|
||||
|
||||
async showCurrentFileDiff(): Promise<void> {
|
||||
@@ -103,6 +110,8 @@ export class DiffViewer {
|
||||
|
||||
// ---- Diff 界面操作 (Bug 1 修复: 自动推进) ----
|
||||
|
||||
// ★ Accept/Reject 后删除临时文件 + 关闭 Diff
|
||||
|
||||
async acceptCurrentDiff(): Promise<void> {
|
||||
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<void> {
|
||||
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; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user