diff options
author | Aubrey Li <Aubrey-Li> | 2021-10-26 17:16:16 -0400 |
---|---|---|
committer | Aubrey Li <Aubrey-Li> | 2021-10-26 17:16:16 -0400 |
commit | 34ce1ba0275406aff180a49f99d333ffa0d86e3b (patch) | |
tree | 25e8ae29b145e5e1e33c59e285f3b29f5a481dc5 /src/client/util/UndoManager.ts | |
parent | 3c1b393732ef9dc704a2f40b103c37b3f8370ba7 (diff) | |
parent | 48d5e650ddc8caa8252561bbc91961f2f4677d6e (diff) |
Merge branch 'master' into trails-aubrey
Diffstat (limited to 'src/client/util/UndoManager.ts')
-rw-r--r-- | src/client/util/UndoManager.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/client/util/UndoManager.ts b/src/client/util/UndoManager.ts index 05fb9f378..44e44d335 100644 --- a/src/client/util/UndoManager.ts +++ b/src/client/util/UndoManager.ts @@ -70,6 +70,7 @@ export namespace UndoManager { export interface UndoEvent { undo: () => void; redo: () => void; + prop: string; } type UndoBatch = UndoEvent[]; @@ -104,6 +105,23 @@ export namespace UndoManager { export function GetOpenBatches(): Without<Batch, 'end'>[] { return openBatches; } + export function FilterBatches(fieldTypes: string[]) { + const fieldCounts: { [key: string]: number } = {}; + const lastStack = UndoManager.undoStack.lastElement(); + if (lastStack) { + lastStack.forEach(ev => fieldTypes.includes(ev.prop) && (fieldCounts[ev.prop] = (fieldCounts[ev.prop] || 0) + 1)); + const fieldCount2: { [key: string]: number } = {}; + runInAction(() => + UndoManager.undoStack[UndoManager.undoStack.length - 1] = lastStack.filter(ev => { + if (fieldTypes.includes(ev.prop)) { + fieldCount2[ev.prop] = (fieldCount2[ev.prop] || 0) + 1; + if (fieldCount2[ev.prop] === 1 || fieldCount2[ev.prop] === fieldCounts[ev.prop]) return true; + return false; + } + return true; + })); + } + } export function TraceOpenBatches() { console.log(`Open batches:\n\t${openBatches.map(batch => batch.batchName).join("\n\t")}\n`); } @@ -140,6 +158,7 @@ export namespace UndoManager { batchCounter--; // console.log("End " + batchCounter); if (batchCounter === 0 && currentBatch?.length) { + // console.log("------ended----") if (!cancel) { undoStack.push(currentBatch); } |