aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/UndoManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/UndoManager.ts')
-rw-r--r--src/client/util/UndoManager.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/client/util/UndoManager.ts b/src/client/util/UndoManager.ts
index 05fb9f378..536d90371 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[]) {
+ var 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));
+ var 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);
}