mirror of
https://github.com/Gmaker689/ai-diff-preview.git
synced 2026-09-27 03:21:52 +08:00
fix: Diff打开后立即触发状态栏刷新 + 临时文件只在Accept/Reject时删除
- showFileDiff/showEditDiff 末尾调用 onDiffAction 通知状态栏切换 Diff 模式 - deleteSessionFiles 独立方法,只在 Accept/Reject 时调用 - clearSession 仅清除会话状态,不删文件(手动关 Diff 后可重新打开)
This commit is contained in:
@@ -3,8 +3,9 @@
|
|||||||
*
|
*
|
||||||
* 关键:
|
* 关键:
|
||||||
* 1. 临时文件(非 untitled)避免保存提示
|
* 1. 临时文件(非 untitled)避免保存提示
|
||||||
* 2. Accept/Reject 后自动推进到下一个 pending 文件
|
* 2. ★ 临时文件只在 Accept/Reject 后删除,手动关闭 Diff 不影响
|
||||||
* 3. 状态栏按钮在 Diff 模式下可见
|
* 3. Accept/Reject 后自动推进到下一个 pending 文件
|
||||||
|
* 4. 状态栏按钮在 Diff 模式下可见
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
@@ -63,6 +64,9 @@ export class DiffViewer {
|
|||||||
this.activeSession!.afterUri,
|
this.activeSession!.afterUri,
|
||||||
`${fileName} — AI ${toolLabel} #${editRecord.id.slice(0, 6)} · 状态栏操作`
|
`${fileName} — AI ${toolLabel} #${editRecord.id.slice(0, 6)} · 状态栏操作`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ★ 通知外部刷新状态栏(切换到 Diff 模式显示 Accept/Reject 按钮)
|
||||||
|
this.onDiffAction?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
async showFileDiff(fileChange: FileChange): Promise<void> {
|
async showFileDiff(fileChange: FileChange): Promise<void> {
|
||||||
@@ -86,6 +90,9 @@ export class DiffViewer {
|
|||||||
this.activeSession!.afterUri,
|
this.activeSession!.afterUri,
|
||||||
`${fileName} — ${fileChange.edits.length} 次 AI 编辑 · 状态栏操作`
|
`${fileName} — ${fileChange.edits.length} 次 AI 编辑 · 状态栏操作`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ★ 通知外部刷新状态栏(切换到 Diff 模式显示 Accept/Reject 按钮)
|
||||||
|
this.onDiffAction?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
async showCurrentFileDiff(): Promise<void> {
|
async showCurrentFileDiff(): Promise<void> {
|
||||||
@@ -103,6 +110,8 @@ export class DiffViewer {
|
|||||||
|
|
||||||
// ---- Diff 界面操作 (Bug 1 修复: 自动推进) ----
|
// ---- Diff 界面操作 (Bug 1 修复: 自动推进) ----
|
||||||
|
|
||||||
|
// ★ Accept/Reject 后删除临时文件 + 关闭 Diff
|
||||||
|
|
||||||
async acceptCurrentDiff(): Promise<void> {
|
async acceptCurrentDiff(): Promise<void> {
|
||||||
if (!this.activeSession) return;
|
if (!this.activeSession) return;
|
||||||
const { fileId, editId } = this.activeSession;
|
const { fileId, editId } = this.activeSession;
|
||||||
@@ -114,10 +123,9 @@ export class DiffViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vscode.window.showInformationMessage('AI Diff: 已接受 ✓');
|
vscode.window.showInformationMessage('AI Diff: 已接受 ✓');
|
||||||
|
this.deleteSessionFiles(); // ★ Accept 后才删
|
||||||
await this.closeDiff();
|
await this.closeDiff();
|
||||||
this.onDiffAction?.();
|
this.onDiffAction?.();
|
||||||
|
|
||||||
// ★ Bug 1 修复: 自动推进到下一个待处理文件
|
|
||||||
this.advanceToNext(fileId);
|
this.advanceToNext(fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,14 +140,12 @@ export class DiffViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vscode.window.showInformationMessage('AI Diff: 已拒绝 ✗');
|
vscode.window.showInformationMessage('AI Diff: 已拒绝 ✗');
|
||||||
|
this.deleteSessionFiles(); // ★ Reject 后才删
|
||||||
await this.closeDiff();
|
await this.closeDiff();
|
||||||
this.onDiffAction?.();
|
this.onDiffAction?.();
|
||||||
|
|
||||||
// ★ Bug 1 修复: 自动推进
|
|
||||||
this.advanceToNext(fileId);
|
this.advanceToNext(fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ★ 接受当前文件的所有编辑 (Diff 界面 Accept All) */
|
|
||||||
async acceptAllFromDiff(): Promise<void> {
|
async acceptAllFromDiff(): Promise<void> {
|
||||||
if (!this.activeSession) return;
|
if (!this.activeSession) return;
|
||||||
const { fileId } = this.activeSession;
|
const { fileId } = this.activeSession;
|
||||||
@@ -147,6 +153,7 @@ export class DiffViewer {
|
|||||||
if (ok) {
|
if (ok) {
|
||||||
vscode.window.showInformationMessage('AI Diff: 已接受此文件全部 ✓');
|
vscode.window.showInformationMessage('AI Diff: 已接受此文件全部 ✓');
|
||||||
}
|
}
|
||||||
|
this.deleteSessionFiles(); // ★ AcceptAll 后才删
|
||||||
await this.closeDiff();
|
await this.closeDiff();
|
||||||
this.onDiffAction?.();
|
this.onDiffAction?.();
|
||||||
this.advanceToNext(fileId);
|
this.advanceToNext(fileId);
|
||||||
@@ -209,8 +216,9 @@ export class DiffViewer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private clearSession(): void {
|
/** ★ 删除当前会话的临时文件(只在 Accept/Reject 时调用) */
|
||||||
if (this.activeSession) {
|
private deleteSessionFiles(): void {
|
||||||
|
if (!this.activeSession) return;
|
||||||
[this.activeSession.beforeTmpPath, this.activeSession.afterTmpPath].forEach(p => {
|
[this.activeSession.beforeTmpPath, this.activeSession.afterTmpPath].forEach(p => {
|
||||||
try { if (fs.existsSync(p)) fs.unlinkSync(p); } catch { /* ok */ }
|
try { if (fs.existsSync(p)) fs.unlinkSync(p); } catch { /* ok */ }
|
||||||
});
|
});
|
||||||
@@ -218,6 +226,9 @@ export class DiffViewer {
|
|||||||
f => f !== this.activeSession!.beforeTmpPath && f !== this.activeSession!.afterTmpPath
|
f => f !== this.activeSession!.beforeTmpPath && f !== this.activeSession!.afterTmpPath
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 清除会话状态(不删文件!手动关闭 Diff 后不影响重新打开) */
|
||||||
|
private clearSession(): void {
|
||||||
this.activeSession = null;
|
this.activeSession = null;
|
||||||
if (this.closeListener) { this.closeListener.dispose(); this.closeListener = null; }
|
if (this.closeListener) { this.closeListener.dispose(); this.closeListener = null; }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user