summaryrefslogtreecommitdiff
path: root/apps/web/src/core/managers/commands.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/core/managers/commands.ts')
-rw-r--r--apps/web/src/core/managers/commands.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/apps/web/src/core/managers/commands.ts b/apps/web/src/core/managers/commands.ts
index 4c53857b..918fc33e 100644
--- a/apps/web/src/core/managers/commands.ts
+++ b/apps/web/src/core/managers/commands.ts
@@ -11,6 +11,7 @@ interface CommandHistoryEntry {
export class CommandManager {
private history: CommandHistoryEntry[] = [];
private redoStack: CommandHistoryEntry[] = [];
+ private reactors: Array<() => void> = [];
constructor(private editor: EditorCore) {}
@@ -18,6 +19,7 @@ export class CommandManager {
const previousSelection = this.getSelectionSnapshot();
const result = command.execute();
const selectionOverride = this.applySelectionOverride(result);
+ this.runReactors();
this.history.push({
command,
previousSelection,
@@ -35,6 +37,10 @@ export class CommandManager {
this.redoStack = [];
}
+ registerReactor(reactor: () => void): void {
+ this.reactors.push(reactor);
+ }
+
undo(): void {
if (this.history.length === 0) return;
const entry = this.history.pop();
@@ -64,6 +70,7 @@ export class CommandManager {
const previousSelection = this.getSelectionSnapshot();
const result = entry.command.redo();
const selectionOverride = this.applySelectionOverride(result);
+ this.runReactors();
this.history.push({
command: entry.command,
@@ -100,4 +107,10 @@ export class CommandManager {
this.editor.selection.setSelectedElements({ elements: selectionOverride });
return selectionOverride;
}
+
+ private runReactors(): void {
+ for (const reactor of this.reactors) {
+ reactor();
+ }
+ }
}