diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-04-06 00:02:23 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-04-06 00:02:23 +0200 |
| commit | 44d8c4c8764d49a8e8d0ae713432c07f07cb7597 (patch) | |
| tree | 4657187279adb475ea710231feb3d0bd4add36ed /apps/web/src/core/managers/commands.ts | |
| parent | 20235d0724a70e6787b6cbdbfa054b1c5d8f62e9 (diff) | |
| download | opencut-44d8c4c8764d49a8e8d0ae713432c07f07cb7597.tar.gz | |
refactor: unify element updates into pipeline and centralize ripple
Diffstat (limited to 'apps/web/src/core/managers/commands.ts')
| -rw-r--r-- | apps/web/src/core/managers/commands.ts | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/apps/web/src/core/managers/commands.ts b/apps/web/src/core/managers/commands.ts index 918fc33e..a3665852 100644 --- a/apps/web/src/core/managers/commands.ts +++ b/apps/web/src/core/managers/commands.ts @@ -1,6 +1,7 @@ import type { EditorCore } from "@/core"; import type { Command, CommandResult } from "@/lib/commands"; -import type { ElementRef } from "@/lib/timeline/types"; +import { applyRippleAdjustments, computeRippleAdjustments } from "@/lib/ripple"; +import type { TimelineTrack, ElementRef } from "@/lib/timeline/types"; interface CommandHistoryEntry { command: Command; @@ -9,6 +10,7 @@ interface CommandHistoryEntry { } export class CommandManager { + public isRippleEnabled = false; private history: CommandHistoryEntry[] = []; private redoStack: CommandHistoryEntry[] = []; private reactors: Array<() => void> = []; @@ -16,8 +18,10 @@ export class CommandManager { constructor(private editor: EditorCore) {} execute({ command }: { command: Command }): Command { + const beforeTracks = this.isRippleEnabled ? this.editor.timeline.getTracks() : null; const previousSelection = this.getSelectionSnapshot(); const result = command.execute(); + this.applyRippleIfEnabled({ beforeTracks }); const selectionOverride = this.applySelectionOverride(result); this.runReactors(); this.history.push({ @@ -67,8 +71,10 @@ export class CommandManager { return; } + const beforeTracks = this.isRippleEnabled ? this.editor.timeline.getTracks() : null; const previousSelection = this.getSelectionSnapshot(); const result = entry.command.redo(); + this.applyRippleIfEnabled({ beforeTracks }); const selectionOverride = this.applySelectionOverride(result); this.runReactors(); @@ -113,4 +119,29 @@ export class CommandManager { reactor(); } } + + private applyRippleIfEnabled({ + beforeTracks, + }: { + beforeTracks: TimelineTrack[] | null; + }): void { + if (!this.isRippleEnabled || !beforeTracks) { + return; + } + + const afterTracks = this.editor.timeline.getTracks(); + const adjustments = computeRippleAdjustments({ + beforeTracks, + afterTracks, + }); + if (adjustments.length === 0) { + return; + } + + const tracksWithRipple = applyRippleAdjustments({ + tracks: afterTracks, + adjustments, + }); + this.editor.timeline.updateTracks(tracksWithRipple); + } } |
