From dc82826951c03cca91ea1431b0b8abdfd9dba583 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Tue, 31 Mar 2026 23:39:43 +0200 Subject: refactor: move track pruning into a post-command reactor --- apps/web/src/core/managers/commands.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'apps/web/src/core/managers/commands.ts') 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(); + } + } } -- cgit v1.3.1