aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/UndoManager.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-09-29 01:38:15 -0400
committerbobzel <zzzman@gmail.com>2021-09-29 01:38:15 -0400
commitaed57a2d6435007676409aeba562fc11d0c4a44d (patch)
treeb14f348cdb1dd78c6d044c0d40ee767888eab2bb /src/client/util/UndoManager.ts
parentfaaa10bfeaf9c4a33a75884c3cf93eb3138464d1 (diff)
a number of undo/redo fixes for ink (snapping to tangent, add points, dragging tangents). also tried to make storage of undo events more efficient when dragging ink controls (avoid saving hundreds of copies of the InkField)
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);
}