mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-29 01:45:54 +08:00
fix: 非连续删除 undo 恢复到错误位置 — OpRecord 新增 indices 精确记录原始位置
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -95,6 +95,18 @@ describe('app-store CRUD', () => {
|
||||
expect(useAppStore.getState().userPaths).toEqual(['A', 'C']);
|
||||
});
|
||||
|
||||
it('deletePaths 非连续多选删除后可 undo 恢复到正确位置', () => {
|
||||
const store = useAppStore.getState();
|
||||
store.addPath('A', TargetType.SYSTEM);
|
||||
store.addPath('B', TargetType.SYSTEM);
|
||||
store.addPath('C', TargetType.SYSTEM);
|
||||
store.addPath('D', TargetType.SYSTEM);
|
||||
store.deletePaths([1, 3], TargetType.SYSTEM);
|
||||
expect(useAppStore.getState().sysPaths).toEqual(['A', 'C']);
|
||||
useAppStore.getState().undo();
|
||||
expect(useAppStore.getState().sysPaths).toEqual(['A', 'B', 'C', 'D']);
|
||||
});
|
||||
|
||||
it('moveUp index=0 无操作', () => {
|
||||
const store = useAppStore.getState();
|
||||
store.addPath('A', TargetType.SYSTEM);
|
||||
|
||||
@@ -128,6 +128,28 @@ describe('UndoRedoManager', () => {
|
||||
expect(small.historyLength).toBe(3);
|
||||
});
|
||||
|
||||
it('非连续多选 DELETE 撤销恢复到原始位置', () => {
|
||||
// 扩展初始数组
|
||||
sys.push('C:\\Extra1', 'C:\\Extra2');
|
||||
const old = [...sys];
|
||||
// 删除 indices [1, 3](C:\Program Files 和 C:\Extra2)
|
||||
const removed = [sys[1], sys[3]];
|
||||
mgr.push({
|
||||
type: OperationType.DELETE, target: TargetType.SYSTEM,
|
||||
index: 1, count: 2,
|
||||
oldPaths: removed, newPaths: [],
|
||||
indices: [1, 3],
|
||||
});
|
||||
sys.splice(3, 1);
|
||||
sys.splice(1, 1);
|
||||
|
||||
const u = mgr.undo(sys, user)!;
|
||||
expect(u[0]).toEqual(old);
|
||||
|
||||
const r = mgr.redo(...u)!;
|
||||
expect(r[0]).toEqual(['C:\\Windows', 'C:\\Extra1']);
|
||||
});
|
||||
|
||||
it('操作 USER 路径', () => {
|
||||
user.push('C:\\NewUserPath');
|
||||
mgr.push(makeRecord(OperationType.ADD, TargetType.USER, 1, 1, [], ['C:\\NewUserPath']));
|
||||
|
||||
Reference in New Issue
Block a user