aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/UndoManager.ts
diff options
context:
space:
mode:
authorMelissa Zhang <mzhang19096@gmail.com>2020-06-18 22:16:57 -0700
committerMelissa Zhang <mzhang19096@gmail.com>2020-06-18 22:16:57 -0700
commitb79b5ebfd4f8ea8b4ae793e59f05b5bfe79b9b8a (patch)
tree3696946f79cd29007e9192fa9a93e5a3a9818a74 /src/client/util/UndoManager.ts
parent8a5c91740f1a8bc4dca2e99bba1da3a1ed1f591b (diff)
parentd8feecd0542670233e6ea87006a89eb00d10a17e (diff)
merge with master
Diffstat (limited to 'src/client/util/UndoManager.ts')
-rw-r--r--src/client/util/UndoManager.ts22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/client/util/UndoManager.ts b/src/client/util/UndoManager.ts
index 314b52bf3..c7b7bb215 100644
--- a/src/client/util/UndoManager.ts
+++ b/src/client/util/UndoManager.ts
@@ -78,10 +78,12 @@ export namespace UndoManager {
let currentBatch: UndoBatch | undefined;
let batchCounter = 0;
let undoing = false;
+ let tempEvents: UndoEvent[] | undefined = undefined;
export function AddEvent(event: UndoEvent): void {
if (currentBatch && batchCounter && !undoing) {
currentBatch.push(event);
+ tempEvents?.push(event);
}
}
@@ -135,7 +137,7 @@ export namespace UndoManager {
const EndBatch = action((cancel: boolean = false) => {
batchCounter--;
- if (batchCounter === 0 && currentBatch && currentBatch.length) {
+ if (batchCounter === 0 && currentBatch?.length) {
if (!cancel) {
undoStack.push(currentBatch);
}
@@ -144,6 +146,13 @@ export namespace UndoManager {
}
});
+ export function ClearTempBatch() {
+ tempEvents = undefined;
+ }
+ export function RunInTempBatch<T>(fn: () => T) {
+ tempEvents = [];
+ return runInAction(fn);
+ }
//TODO Make this return the return value
export function RunInBatch<T>(fn: () => T, batchName: string) {
const batch = StartBatch(batchName);
@@ -153,7 +162,16 @@ export namespace UndoManager {
batch.end();
}
}
-
+ export const UndoTempBatch = action(() => {
+ if (tempEvents) {
+ undoing = true;
+ for (let i = tempEvents.length - 1; i >= 0; i--) {
+ tempEvents[i].undo();
+ }
+ undoing = false;
+ }
+ tempEvents = undefined;
+ });
export const Undo = action(() => {
if (undoStack.length === 0) {
return;