summaryrefslogtreecommitdiff
path: root/apps/web/src/core/managers/commands.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-03-31 23:39:43 +0200
committerMaze Winther <mazewinther@gmail.com>2026-03-31 23:39:43 +0200
commitdc82826951c03cca91ea1431b0b8abdfd9dba583 (patch)
tree34b8eedf1cb7709ecb5b0607a0b55cd9eea88cfc /apps/web/src/core/managers/commands.ts
parentf8fb238b228881ef970739b7d884912058b41347 (diff)
downloadopencut-dc82826951c03cca91ea1431b0b8abdfd9dba583.tar.gz
refactor: move track pruning into a post-command reactor
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();
+ }
+ }
}