Batch caption text insertion
[Modified from eece3bbc5f0578a24a4f90f0ab87fe5ca37e94e9, 2026-03-28 09:13:18 -0400] Batch caption insertion in a BatchCommand so that undo will batch undo all subtitle insertion from either srt file or ai transcriptions.
This commit is contained in:
parent
63fa3821fa
commit
b85d8ebb52
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue