diff --git a/apps/web/src/lib/subtitles/insert.ts b/apps/web/src/lib/subtitles/insert.ts index 5a64b8fe..5d943fc9 100644 --- a/apps/web/src/lib/subtitles/insert.ts +++ b/apps/web/src/lib/subtitles/insert.ts @@ -1,6 +1,11 @@ import type { EditorCore } from "@/core"; import { DEFAULTS } from "@/lib/timeline/defaults"; import type { CaptionChunk } from "@/lib/transcription/types"; +import { + AddTrackCommand, + BatchCommand, + InsertElementCommand, +} from "@/lib/commands"; export function insertCaptionChunksAsTextTrack({ editor, @@ -13,26 +18,31 @@ export function insertCaptionChunksAsTextTrack({ return null; } - const trackId = editor.timeline.addTrack({ - type: "text", - index: 0, - }); + const addTrackCommand = new AddTrackCommand("text", 0); + const trackId = addTrackCommand.getTrackId(); + const commands = [addTrackCommand]; for (let i = 0; i < captions.length; i++) { const caption = captions[i]; - editor.timeline.insertElement({ - placement: { mode: "explicit", trackId }, - element: { - ...DEFAULTS.text.element, - name: `Caption ${i + 1}`, - content: caption.text, - duration: caption.duration, - startTime: caption.startTime, - fontSize: 65, - fontWeight: "bold", - }, - }); + commands.push( + new InsertElementCommand({ + placement: { mode: "explicit", trackId }, + element: { + ...DEFAULTS.text.element, + name: `Caption ${i + 1}`, + content: caption.text, + duration: caption.duration, + startTime: caption.startTime, + fontSize: 65, + fontWeight: "bold", + }, + }), + ); } + editor.command.execute({ + command: new BatchCommand(commands), + }); + return trackId; }