summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/commands/timeline/element/duplicate-elements.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-03-31 15:53:23 +0200
committerMaze Winther <mazewinther@gmail.com>2026-03-31 15:53:23 +0200
commitd23be079cce6108482fc3e85401cccf949087174 (patch)
tree7d5acd324f9274b3b823bc67154349b8693e3412 /apps/web/src/lib/commands/timeline/element/duplicate-elements.ts
parentdcf54c1250431f5a4a2848f7c07781ef5eebacaf (diff)
parent70a6d58b8432e455ab1443d45bc23dd70b363bea (diff)
downloadopencut-d23be079cce6108482fc3e85401cccf949087174.tar.gz
Merge branch 'feature/track-placement'
Diffstat (limited to 'apps/web/src/lib/commands/timeline/element/duplicate-elements.ts')
-rw-r--r--apps/web/src/lib/commands/timeline/element/duplicate-elements.ts46
1 files changed, 25 insertions, 21 deletions
diff --git a/apps/web/src/lib/commands/timeline/element/duplicate-elements.ts b/apps/web/src/lib/commands/timeline/element/duplicate-elements.ts
index 346f8c73..a4f7ca82 100644
--- a/apps/web/src/lib/commands/timeline/element/duplicate-elements.ts
+++ b/apps/web/src/lib/commands/timeline/element/duplicate-elements.ts
@@ -2,10 +2,7 @@ import { Command } from "@/lib/commands/base-command";
import type { TimelineElement, TimelineTrack } from "@/lib/timeline";
import { generateUUID } from "@/utils/id";
import { EditorCore } from "@/core";
-import {
- buildEmptyTrack,
- getHighestInsertIndexForTrack,
-} from "@/lib/timeline/track-utils";
+import { applyPlacement, resolveTrackPlacement } from "@/lib/timeline/placement";
import { cloneAnimations } from "@/lib/animation";
interface DuplicateElementsParams {
@@ -45,22 +42,12 @@ export class DuplicateElementsCommand extends Command {
);
const newTrackElements: TimelineElement[] = [];
- const newTrackId = generateUUID();
- const newTrackBase = buildEmptyTrack({
- id: newTrackId,
- type: track.type,
- });
-
for (const element of track.elements) {
if (!elementIdsToDuplicate.has(element.id)) {
continue;
}
const newId = generateUUID();
- this.duplicatedElements.push({
- trackId: newTrackId,
- elementId: newId,
- });
newTrackElements.push(
buildDuplicateElement({
element,
@@ -70,16 +57,33 @@ export class DuplicateElementsCommand extends Command {
);
}
- const newTrack = {
- ...newTrackBase,
- elements: newTrackElements,
- } as TimelineTrack;
-
- const insertIndex = getHighestInsertIndexForTrack({
+ const placementResult = resolveTrackPlacement({
tracks: updatedTracks,
trackType: track.type,
+ timeSpans: [],
+ strategy: { type: "alwaysNew", position: "highest" },
});
- updatedTracks.splice(insertIndex, 0, newTrack);
+ if (!placementResult || placementResult.kind !== "newTrack") {
+ continue;
+ }
+
+ const applied = applyPlacement({
+ tracks: updatedTracks,
+ placementResult,
+ elements: newTrackElements,
+ });
+ if (!applied) {
+ continue;
+ }
+
+ updatedTracks = applied.updatedTracks;
+
+ for (const element of newTrackElements) {
+ this.duplicatedElements.push({
+ trackId: applied.targetTrackId,
+ elementId: element.id,
+ });
+ }
}
editor.timeline.updateTracks(updatedTracks);