Skip to content

Open source CapCut alternative.

TypeScript

fix(cut): removing the only subtitle track clears it [rebuild]

David Le4e493b1b3083
diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.ts
index 71da41c9..df118505 100644
--- a/site/src/cut/lib/aiTools.ts
+++ b/site/src/cut/lib/aiTools.ts
@@ -1284,7 +1284,13 @@ export async function runAiTool(
const lane = Math.round(input.track);
const count = subtitleLaneCount(s.subtitles);
if (lane < 0 || lane >= count) throw new ToolError(`No subtitle track ${lane}.`);
- if (count <= 1) throw new ToolError("The last subtitle track can't be removed.");
+ if (count <= 1) {
+ // The editor always keeps one lane, so removing the only track
+ // empties it instead.
+ const cleared = laneCues(s.subtitles, 0).length;
+ s.removeSubtitleTrack(0);
+ return { track: 0, tracks: 1, clearedCues: cleared };
+ }
s.removeSubtitleTrack(lane);
return { removed: lane, tracks: count - 1 };
}
diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.ts
index a86ecdea..5660e02e 100644
--- a/site/src/cut/lib/store.ts
+++ b/site/src/cut/lib/store.ts
@@ -2412,7 +2412,33 @@ export const useEditor = create<EditorState>((baseSet, get) => {
s.subtitles.tracks?.length ?? 0,
...s.subtitles.cues.map((c) => (c.lane ?? 0) + 1)
);
- if (count <= 1) return;
+ if (count <= 1) {
+ // The editor always keeps one subtitle lane, so removing the only
+ // track empties it: cues, language, and dragged anchor all reset.
+ if (s.subtitles.cues.length === 0) return;
+ push();
+ laneEpoch++; // invalidate in-flight lane-targeted work
+ const keep = (sel: Selection) => !!sel && sel.kind !== "cue";
+ set((cur) => {
+ const multiSelection = cur.multiSelection.filter(keep);
+ return {
+ subtitles: {
+ ...cur.subtitles,
+ tracks: undefined,
+ locale: undefined,
+ x: undefined,
+ y: undefined,
+ cues: [],
+ },
+ subtitleLane: 0,
+ multiSelection,
+ selection: keep(cur.selection)
+ ? cur.selection
+ : multiSelection[multiSelection.length - 1] ?? null,
+ };
+ });
+ return;
+ }
push();
laneEpoch++; // lanes renumber: invalidate in-flight lane-targeted work
const gone = new Set(
diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.ts
index caa48d0c..43c586f8 100644
--- a/site/src/cut/server/ai/catalog.ts
+++ b/site/src/cut/server/ai/catalog.ts
@@ -520,7 +520,8 @@ export const AI_TOOLS: AiToolDef[] = [
},
{
name: "subtitles_remove_track",
- description: "Remove a subtitle track and its captions; higher tracks shift down.",
+ description:
+ "Remove a subtitle track and its captions; higher tracks shift down. Removing the only track empties it — so this also answers \"delete the subtitles\".",
inputSchema: obj({ track: num("Track to remove, 0-based") }, ["track"]),
},
{