From 32287c0e4bd5fa485b7f521a4ee280f4e9d20a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=88=AA=E5=AE=87?= <3364451258@qq.com> Date: Wed, 27 May 2026 13:32:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20PathEntry=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=20+=20TOGGLE=20=E6=93=8D=E4=BD=9C=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8Cundo-redo=20=E7=94=A8=20PathEntry[]=20?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3=20string[]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- src/core/path-entry.ts | 5 +++++ src/core/undo-redo.ts | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 src/core/path-entry.ts diff --git a/src/core/path-entry.ts b/src/core/path-entry.ts new file mode 100644 index 0000000..1f389a2 --- /dev/null +++ b/src/core/path-entry.ts @@ -0,0 +1,5 @@ +/** PATH 路径条目 — 包含路径值和启用状态 */ +export interface PathEntry { + path: string; + enabled: boolean; +} diff --git a/src/core/undo-redo.ts b/src/core/undo-redo.ts index d38722b..15ecdb8 100644 --- a/src/core/undo-redo.ts +++ b/src/core/undo-redo.ts @@ -1,9 +1,11 @@ /** - * 撤销/重做管理器 — 纯逻辑,操作不可变 string[] + * 撤销/重做管理器 — 纯逻辑,操作不可变 PathEntry[] */ +import type { PathEntry } from './path-entry'; + export const OperationType = { - ADD: 0, DELETE: 1, EDIT: 2, MOVE_UP: 3, MOVE_DOWN: 4, CLEAN: 5, CLEAR: 6, IMPORT: 7, + ADD: 0, DELETE: 1, EDIT: 2, MOVE_UP: 3, MOVE_DOWN: 4, CLEAN: 5, CLEAR: 6, IMPORT: 7, TOGGLE: 8, } as const; export type OperationType = (typeof OperationType)[keyof typeof OperationType]; @@ -15,8 +17,8 @@ export interface OpRecord { target: TargetType; index: number; count: number; - oldPaths: string[]; - newPaths: string[]; + oldPaths: PathEntry[]; + newPaths: PathEntry[]; /** DELETE 操作专用:被删除的各路径的原始 index(升序) */ indices?: number[]; } @@ -41,7 +43,7 @@ export class UndoRedoManager { this.current = this.records.length - 1; } - undo(sysPaths: readonly string[], userPaths: readonly string[]): [string[], string[]] | null { + undo(sysPaths: readonly PathEntry[], userPaths: readonly PathEntry[]): [PathEntry[], PathEntry[]] | null { if (this.current < 0) return null; const rec = this.records[this.current]; @@ -83,12 +85,15 @@ export class UndoRedoManager { case OperationType.CLEAR: target.push(...rec.oldPaths); break; + case OperationType.TOGGLE: + target[rec.index] = rec.oldPaths[0]; + break; } return [sys, user]; } - redo(sysPaths: readonly string[], userPaths: readonly string[]): [string[], string[]] | null { + redo(sysPaths: readonly PathEntry[], userPaths: readonly PathEntry[]): [PathEntry[], PathEntry[]] | null { if (this.current >= this.records.length - 1) return null; this.current++; @@ -130,6 +135,9 @@ export class UndoRedoManager { case OperationType.CLEAR: target.length = 0; break; + case OperationType.TOGGLE: + target[rec.index] = rec.newPaths[0]; + break; } return [sys, user];