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.ts33
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);
+ }
}