Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
feat(editor): show what a trim keeps, while the handles are still moving
超超超超超级喜欢你的达妮娅edf72555ff21
diff --git a/src/components/ai-edition/EditClipModal.test.tsx b/src/components/ai-edition/EditClipModal.test.tsxnew file mode 100644index 000000000..eb12ad059--- /dev/null+++ b/src/components/ai-edition/EditClipModal.test.tsx@@ -0,0 +1,145 @@+// @vitest-environment jsdom+import "@testing-library/jest-dom";+import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";+import type { ReactElement } from "react";+import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";+import { I18nProvider } from "@/contexts/I18nContext";+import type { AxcutClip } from "@/lib/ai-edition/schema";+import { EditClipModal } from "./Modals";++function renderWithI18n(ui: ReactElement) {+ return render(<I18nProvider>{ui}</I18nProvider>);+}++/** Issue #558's example: original 2:35, keep 0:20–1:45, final 1:25. */+const CLIP: AxcutClip = {+ id: "clip_1",+ assetId: "asset_1",+ sourceStartSec: 20,+ sourceEndSec: 105,+ timelineStartSec: 0,+ timelineEndSec: 85,+ wordRefs: [],+ origin: "user",+ reason: "",+};++const ASSET = { label: "rec", durationSec: 155 };++beforeAll(() => {+ // The trim-handle drag converts pointer delta against the track width into+ // seconds. jsdom reports 0, which would make every drag a no-op.+ Object.defineProperty(HTMLElement.prototype, "clientWidth", {+ configurable: true,+ get() {+ return this.getAttribute?.("data-testid") === "edit-clip-trim-track" ? 1550 : 0;+ },+ });+});++afterEach(() => {+ cleanup();+ vi.clearAllMocks();+});++function renderModal(clip: AxcutClip = CLIP) {+ return renderWithI18n(+ <EditClipModal+ open+ onClose={vi.fn()}+ clip={clip}+ assetMeta={ASSET}+ videoSources={[]}+ onApply={vi.fn()}+ />,+ );+}++describe("EditClipModal trim duration readout (#558)", () => {+ it("shows original duration, trim range, and final duration for the selected range", () => {+ renderModal();++ expect(screen.getByTestId("edit-clip-original-duration")).toHaveTextContent("2:35.0");+ expect(screen.getByTestId("edit-clip-original-duration")).toHaveTextContent(+ "Original duration",+ );+ expect(screen.getByTestId("edit-clip-trim-range")).toHaveTextContent("0:20.0–1:45.0");+ expect(screen.getByTestId("edit-clip-trim-range")).toHaveTextContent("Trim range");+ expect(screen.getByTestId("edit-clip-final-duration")).toHaveTextContent("1:25.0");+ expect(screen.getByTestId("edit-clip-final-duration")).toHaveTextContent("Final duration");+ });++ it("updates the final duration as the start handle is dragged", () => {+ renderModal();++ fireEvent.pointerDown(screen.getByRole("button", { name: "Adjust clip start" }), {+ clientX: 0,+ });+ act(() => {+ window.dispatchEvent(new MouseEvent("pointermove", { clientX: 100 }));+ });++ expect(screen.getByTestId("edit-clip-original-duration")).toHaveTextContent("2:35.0");+ expect(screen.getByTestId("edit-clip-trim-range")).toHaveTextContent("0:30.0–1:45.0");+ expect(screen.getByTestId("edit-clip-final-duration")).toHaveTextContent("1:15.0");+ });++ it("will not pass the out-point off as the source length", () => {+ // `durationSec` is optional in the asset schema, so a document can reach+ // this dialog without one. The track still has to be drawn against+ // something that contains the selection (the out-point), but calling that+ // the original duration would claim a 2:35 source was 1:45 long.+ renderWithI18n(+ <EditClipModal+ open+ onClose={vi.fn()}+ clip={CLIP}+ assetMeta={{ label: "rec" }}+ videoSources={[]}+ onApply={vi.fn()}+ />,+ );++ expect(screen.getByTestId("edit-clip-original-duration")).toHaveTextContent("—");+ expect(screen.getByTestId("edit-clip-original-duration")).not.toHaveTextContent("1:45.0");+ // The kept range and its length are still known, and still shown.+ expect(screen.getByTestId("edit-clip-trim-range")).toHaveTextContent("0:20.0–1:45.0");+ expect(screen.getByTestId("edit-clip-final-duration")).toHaveTextContent("1:25.0");+ });++ it("states the kept range once, in the stats row", () => {+ renderModal();++ // The range used to be printed a second time inside the selection bar, 40px+ // under the stat that now carries it. One reading of a number is enough.+ expect(screen.getAllByText("0:20.0–1:45.0")).toHaveLength(1);+ });++ it("keeps the discarded head and tail out of the pointer's way", () => {+ const { container } = renderModal();++ // The dimmed tail is painted after the selection, so it covers the end+ // handle's 6px overhang and, once the range is narrower than the handle,+ // the handle itself. jsdom does not hit-test, so this pins the property+ // rather than the grab; the grab is checked by driving the real window.+ const dimmed = [...container.querySelectorAll<HTMLElement>("div")].filter(+ (el) => el.style.background === "var(--overlay-dark)",+ );+ expect(dimmed).toHaveLength(2);+ for (const el of dimmed) expect(el.style.pointerEvents).toBe("none");+ });++ it("updates the final duration as the end handle is dragged", () => {+ renderModal();++ fireEvent.pointerDown(screen.getByRole("button", { name: "Adjust clip end" }), {+ clientX: 0,+ });+ act(() => {+ window.dispatchEvent(new MouseEvent("pointermove", { clientX: -50 }));+ });++ expect(screen.getByTestId("edit-clip-trim-range")).toHaveTextContent("0:20.0–1:40.0");+ expect(screen.getByTestId("edit-clip-final-duration")).toHaveTextContent("1:20.0");+ });+});diff --git a/src/components/ai-edition/Modals.tsx b/src/components/ai-edition/Modals.tsxindex f74c68a78..f24500224 100644--- a/src/components/ai-edition/Modals.tsx+++ b/src/components/ai-edition/Modals.tsx@@ -771,7 +771,22 @@ export function EditClipModal({if (!clip) return null;- const sourceDurationSec = Math.max(assetMeta?.durationSec ?? 0, clip.sourceEndSec ?? 0, 0.001);+ // The asset's own length, or null when the document never carried one+ // (`durationSec` is optional in the schema, and an unprobed import has none).+ // Only this may be shown as the original duration.+ const assetDurationSec =+ assetMeta?.durationSec && assetMeta.durationSec > 0 ? assetMeta.durationSec : null;+ // What the track is drawn against. It has to hold the selection whatever the+ // metadata says, so it falls back to the out-point — which is why it cannot+ // double as the original-duration readout: with no asset duration it would+ // report the current trim end as the source length.+ const sourceDurationSec = Math.max(assetDurationSec ?? 0, clip.sourceEndSec ?? 0, 0.001);+ // What the trim keeps, on the raw ruler — the same clock the timeline, the+ // transport readout and the clip cards all run on. A speed region does change+ // how long that span PLAYS (`outputDurationOfRawSpan` integrates 1/speed for+ // the export and audio paths), but nothing in the editor's own chrome reports+ // playback time, so scaling it here alone would disagree with the ruler+ // directly above this dialog.const durationSec = Math.max(0.001, draftEnd - draftStart);const hasTrimChanges =Math.abs(draftStart - clip.sourceStartSec) > 0.001 ||@@ -1090,10 +1105,26 @@ export function EditClipModal({</div><div style={{ flexShrink: 0 }}>- <div style={{ display: "flex", gap: 24, marginBottom: 10 }}>- <RangeStat label={t("editClipDialog.start")} value={formatSeconds(draftStart)} />- <RangeStat label={t("editClipDialog.end")} value={formatSeconds(draftEnd)} />- <RangeStat label={t("editClipDialog.duration")} value={formatSeconds(durationSec)} />+ <div+ style={{ display: "flex", gap: 24, marginBottom: 10 }}+ aria-live="polite"+ aria-atomic="true"+ >+ <RangeStat+ label={t("editClipDialog.originalDuration")}+ value={assetDurationSec === null ? "—" : formatSeconds(assetDurationSec)}+ testId="edit-clip-original-duration"+ />+ <RangeStat+ label={t("editClipDialog.trimRange")}+ value={`${formatSeconds(draftStart)}–${formatSeconds(draftEnd)}`}+ testId="edit-clip-trim-range"+ />+ <RangeStat+ label={t("editClipDialog.duration")}+ value={formatSeconds(durationSec)}+ testId="edit-clip-final-duration"+ /></div><div@@ -1110,6 +1141,7 @@ export function EditClipModal({</div><divref={trackRef}+ data-testid="edit-clip-trim-track"style={{position: "relative",height: 32,@@ -1118,6 +1150,7 @@ export function EditClipModal({borderRadius: "var(--r-sm)",}}>+ {/* Dimmed, discarded head. Decoration only — see the tail below. */}<divstyle={{position: "absolute",@@ -1125,6 +1158,7 @@ export function EditClipModal({width: `${(draftStart / sourceDurationSec) * 100}%`,background: "var(--overlay-dark)",borderRadius: "var(--r-sm) 0 0 var(--r-sm)",+ pointerEvents: "none",}}/><div@@ -1138,9 +1172,6 @@ export function EditClipModal({background: "var(--accent-wash)",border: "1px solid var(--accent)",borderRadius: "var(--r-sm)",- display: "flex",- alignItems: "center",- justifyContent: "center",}}><button@@ -1161,16 +1192,6 @@ export function EditClipModal({padding: 0,}}/>- <span- style={{- font: "500 11px/1.4 var(--font-mono)",- color: "var(--accent-on)",- pointerEvents: "none",- whiteSpace: "nowrap",- }}- >- {formatSeconds(draftStart)}–{formatSeconds(draftEnd)}- </span><buttontype="button"onPointerDown={(e) => startDrag("end", e)}@@ -1190,6 +1211,11 @@ export function EditClipModal({}}/></div>+ {/* Dimmed, discarded tail. It is painted after the selection, so it sits+ ABOVE the end handle that overhangs the selection's right edge by 6px:+ without pointer-events:none it swallows the grab as soon as the range is+ narrower than the handle, and a range dragged down to the 0.05s minimum+ can then only be recovered with Reset. */}<divstyle={{position: "absolute",@@ -1199,6 +1225,7 @@ export function EditClipModal({width: `${Math.max(0, ((sourceDurationSec - draftEnd) / sourceDurationSec) * 100)}%`,background: "var(--overlay-dark)",borderRadius: "0 var(--r-sm) var(--r-sm) 0",+ pointerEvents: "none",}}/></div>@@ -1331,9 +1358,9 @@ export function EditClipModal({);}-function RangeStat({ label, value }: { label: string; value: string }) {+function RangeStat({ label, value, testId }: { label: string; value: string; testId?: string }) {return (- <div style={{ display: "flex", flexDirection: "column", gap: 2 }}>+ <div data-testid={testId} style={{ display: "flex", flexDirection: "column", gap: 2 }}><strong style={{ font: "600 15px/1.2 var(--font-mono)", color: "var(--fg)" }}>{value}</strong><small style={{ font: "500 10px/1.4 var(--font-body)", color: "var(--muted)" }}>{label}diff --git a/src/components/ai-edition/v4/EditorShellV4.module.css b/src/components/ai-edition/v4/EditorShellV4.module.cssindex 787d42292..4b456274d 100644--- a/src/components/ai-edition/v4/EditorShellV4.module.css+++ b/src/components/ai-edition/v4/EditorShellV4.module.css@@ -1971,6 +1971,12 @@overflow: hidden;text-overflow: ellipsis;}+.tlClipDuration {+ font: 500 10px/1.2 var(--font-mono);+ color: rgba(255, 255, 255, 0.7);+ white-space: nowrap;+ flex-shrink: 0;+}.tlClipDelete {position: absolute;right: 8px;diff --git a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsxindex 6cbc72def..8ab72384c 100644--- a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx+++ b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx@@ -461,6 +461,28 @@ describe("V4Timeline clip row", () => {expect(pill.style.left).toBe(clipEls[1].style.left);});+ it("shows each clip's edited duration on the card", () => {+ renderTimeline(CLIPS);+ // 600s / 300s / 900s of an 1800s source: each card reads the clip's own+ // length on the timeline (out − in), not the asset's original length. A+ // speed region over the clip changes how long it plays, not this number.+ expect(screen.getByText("10:00.0")).toBeInTheDocument();+ expect(screen.getByText("5:00.0")).toBeInTheDocument();+ expect(screen.getByText("15:00.0")).toBeInTheDocument();+ });++ it("withholds the duration from a card too small to hold it", () => {+ // 250s at this zoom is a 125px card: past the narrow gate, so it still shows+ // its name and pencil, but not wide enough for the timecode — which would+ // otherwise escape the label pill and sit on the delete button. Measured in+ // the running window, not derived here.+ renderTimeline([clip(0, 250), clip(250, TOTAL_SEC)]);++ expect(screen.queryByText("4:10.0")).not.toBeInTheDocument();+ // The card that does have the room still reads its length.+ expect(screen.getByText("25:50.0")).toBeInTheDocument();+ });+it("takes the card gutter out of each clip's own width", () => {// The 6px is what separates two cards. Taken off the clip's width it stays// local to that clip; inserted between them (a flex gap) it displaced everydiff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsxindex 502122a84..17d2d6bc3 100644--- a/src/components/ai-edition/v4/V4Timeline.tsx+++ b/src/components/ai-edition/v4/V4Timeline.tsx@@ -151,6 +151,12 @@ const PILL_SNAP_PX = 8;* clips that follow — which is what a flex `gap` did, once per junction. *//** Below this a clip cannot show a label and a delete button inside itself. */const NARROW_CLIP_PX = 120;+// A card wide enough to also carry its edited duration. The label pill is capped+// at `calc(100% - 50px)` to clear the delete button, and its incompressible+// content — padding, the pencil, two gaps and the timecode — is ~76px, so below+// this the timecode escapes the pill and lands on that button. Measured in the+// running window: overlapping at 121px, clean from 131px.+const CLIP_DURATION_PX = 132;const CLIP_GUTTER_PX = 6;/**@@ -2232,6 +2238,9 @@ export function V4Timeline({<span className={styles.tlClipName}>{tl.assets.find((a) => a.id === c.assetId)?.label ?? c.assetId}</span>+ {boxLen * pxPerSec >= CLIP_DURATION_PX ? (+ <span className={styles.tlClipDuration}>{formatSec(dur)}</span>+ ) : null}</div>{selected ? (<buttondiff --git a/src/i18n/locales/ar/editor.json b/src/i18n/locales/ar/editor.jsonindex 98e0f38f0..3768c7f64 100644--- a/src/i18n/locales/ar/editor.json+++ b/src/i18n/locales/ar/editor.json@@ -314,9 +314,9 @@"title": "تعديل المقطع","adjustStart": "ضبط بداية المقطع","adjustEnd": "ضبط نهاية المقطع",- "start": "البداية",- "end": "النهاية",- "duration": "المدة",+ "originalDuration": "المدة الأصلية",+ "trimRange": "نطاق القص",+ "duration": "المدة النهائية","reset": "إعادة التعيين","apply": "تطبيق","pickClipTitle": "اختر مقطعًا لتعديله",diff --git a/src/i18n/locales/en/editor.json b/src/i18n/locales/en/editor.jsonindex 2c4ddc248..dfd04c420 100644--- a/src/i18n/locales/en/editor.json+++ b/src/i18n/locales/en/editor.json@@ -314,9 +314,9 @@"title": "Edit clip","adjustStart": "Adjust clip start","adjustEnd": "Adjust clip end",- "start": "Start",- "end": "End",- "duration": "Duration",+ "originalDuration": "Original duration",+ "trimRange": "Trim range",+ "duration": "Final duration","reset": "Reset","apply": "Apply","pickClipTitle": "Choose a clip to edit",diff --git a/src/i18n/locales/es/editor.json b/src/i18n/locales/es/editor.jsonindex 68b3fbc2c..bfc420d58 100644--- a/src/i18n/locales/es/editor.json+++ b/src/i18n/locales/es/editor.json@@ -314,9 +314,9 @@"title": "Editar clip","adjustStart": "Ajustar inicio del clip","adjustEnd": "Ajustar fin del clip",- "start": "Inicio",- "end": "Fin",- "duration": "Duración",+ "originalDuration": "Duración original",+ "trimRange": "Rango de recorte",+ "duration": "Duración final","reset": "Restablecer","apply": "Aplicar","pickClipTitle": "Elige un clip para editar",diff --git a/src/i18n/locales/fr/editor.json b/src/i18n/locales/fr/editor.jsonindex b38fff0b6..16787be61 100644--- a/src/i18n/locales/fr/editor.json+++ b/src/i18n/locales/fr/editor.json@@ -314,9 +314,9 @@"title": "Modifier le clip","adjustStart": "Ajuster le début du clip","adjustEnd": "Ajuster la fin du clip",- "start": "Début",- "end": "Fin",- "duration": "Durée",+ "originalDuration": "Durée d'origine",+ "trimRange": "Plage de coupe",+ "duration": "Durée finale","reset": "Réinitialiser","apply": "Appliquer","pickClipTitle": "Choisissez un clip à modifier",diff --git a/src/i18n/locales/it/editor.json b/src/i18n/locales/it/editor.jsonindex 00a092ee7..288e2dc91 100644--- a/src/i18n/locales/it/editor.json+++ b/src/i18n/locales/it/editor.json@@ -314,9 +314,9 @@"title": "Modifica clip","adjustStart": "Regola l'inizio della clip","adjustEnd": "Regola la fine della clip",- "start": "Inizio",- "end": "Fine",- "duration": "Durata",+ "originalDuration": "Durata originale",+ "trimRange": "Intervallo di taglio",+ "duration": "Durata finale","reset": "Reimposta","apply": "Applica","pickClipTitle": "Scegli una clip da modificare",diff --git a/src/i18n/locales/ja-JP/editor.json b/src/i18n/locales/ja-JP/editor.jsonindex b8f600334..3b9da716b 100644--- a/src/i18n/locales/ja-JP/editor.json+++ b/src/i18n/locales/ja-JP/editor.json@@ -314,9 +314,9 @@"title": "クリップを編集","adjustStart": "クリップの開始位置を調整","adjustEnd": "クリップの終了位置を調整",- "start": "開始",- "end": "終了",- "duration": "長さ",+ "originalDuration": "元の長さ",+ "trimRange": "トリム範囲",+ "duration": "最終の長さ","reset": "リセット","apply": "適用","pickClipTitle": "編集するクリップを選択",diff --git a/src/i18n/locales/ko-KR/editor.json b/src/i18n/locales/ko-KR/editor.jsonindex 2f382d135..746cf6349 100644--- a/src/i18n/locales/ko-KR/editor.json+++ b/src/i18n/locales/ko-KR/editor.json@@ -314,9 +314,9 @@"title": "클립 편집","adjustStart": "클립 시작 지점 조정","adjustEnd": "클립 종료 지점 조정",- "start": "시작",- "end": "종료",- "duration": "길이",+ "originalDuration": "원본 길이",+ "trimRange": "트림 범위",+ "duration": "최종 길이","reset": "재설정","apply": "적용","pickClipTitle": "편집할 클립 선택",diff --git a/src/i18n/locales/pt-BR/editor.json b/src/i18n/locales/pt-BR/editor.jsonindex 7bdb2a2d4..5140df314 100644--- a/src/i18n/locales/pt-BR/editor.json+++ b/src/i18n/locales/pt-BR/editor.json@@ -314,9 +314,9 @@"title": "Editar clipe","adjustStart": "Ajustar início do clipe","adjustEnd": "Ajustar fim do clipe",- "start": "Início",- "end": "Fim",- "duration": "Duração",+ "originalDuration": "Duração original",+ "trimRange": "Intervalo de corte",+ "duration": "Duração final","reset": "Redefinir","apply": "Aplicar","pickClipTitle": "Escolha um clipe para editar",diff --git a/src/i18n/locales/ru/editor.json b/src/i18n/locales/ru/editor.jsonindex dd531e56b..3a384dce6 100644--- a/src/i18n/locales/ru/editor.json+++ b/src/i18n/locales/ru/editor.json@@ -314,9 +314,9 @@"title": "Изменить клип","adjustStart": "Настроить начало клипа","adjustEnd": "Настроить конец клипа",- "start": "Начало",- "end": "Конец",- "duration": "Длительность",+ "originalDuration": "Исходная длительность",+ "trimRange": "Диапазон обрезки",+ "duration": "Итоговая длительность","reset": "Сбросить","apply": "Применить","pickClipTitle": "Выберите клип для редактирования",diff --git a/src/i18n/locales/tr/editor.json b/src/i18n/locales/tr/editor.jsonindex b94ba0e84..3d5857891 100644--- a/src/i18n/locales/tr/editor.json+++ b/src/i18n/locales/tr/editor.json@@ -314,9 +314,9 @@"title": "Klibi düzenle","adjustStart": "Klip başlangıcını ayarla","adjustEnd": "Klip bitişini ayarla",- "start": "Başlangıç",- "end": "Bitiş",- "duration": "Süre",+ "originalDuration": "Orijinal süre",+ "trimRange": "Kırpma aralığı",+ "duration": "Son süre","reset": "Sıfırla","apply": "Uygula","pickClipTitle": "Düzenlenecek klibi seçin",diff --git a/src/i18n/locales/vi/editor.json b/src/i18n/locales/vi/editor.jsonindex 59ba3489b..e6d843416 100644--- a/src/i18n/locales/vi/editor.json+++ b/src/i18n/locales/vi/editor.json@@ -314,9 +314,9 @@"title": "Chỉnh sửa clip","adjustStart": "Điều chỉnh điểm bắt đầu clip","adjustEnd": "Điều chỉnh điểm kết thúc clip",- "start": "Bắt đầu",- "end": "Kết thúc",- "duration": "Thời lượng",+ "originalDuration": "Thời lượng gốc",+ "trimRange": "Phạm vi cắt",+ "duration": "Thời lượng cuối","reset": "Đặt lại","apply": "Áp dụng","pickClipTitle": "Chọn clip để chỉnh sửa",diff --git a/src/i18n/locales/zh-CN/editor.json b/src/i18n/locales/zh-CN/editor.jsonindex 7c3a6d98e..1a0677f39 100644--- a/src/i18n/locales/zh-CN/editor.json+++ b/src/i18n/locales/zh-CN/editor.json@@ -314,9 +314,9 @@"title": "编辑片段","adjustStart": "调整片段起点","adjustEnd": "调整片段终点",- "start": "起点",- "end": "终点",- "duration": "时长",+ "originalDuration": "原始时长",+ "trimRange": "裁剪范围",+ "duration": "最终时长","reset": "重置","apply": "应用","pickClipTitle": "选择要编辑的片段",diff --git a/src/i18n/locales/zh-TW/editor.json b/src/i18n/locales/zh-TW/editor.jsonindex fefdaf004..cd04d873e 100644--- a/src/i18n/locales/zh-TW/editor.json+++ b/src/i18n/locales/zh-TW/editor.json@@ -314,9 +314,9 @@"title": "編輯片段","adjustStart": "調整片段起點","adjustEnd": "調整片段終點",- "start": "起點",- "end": "終點",- "duration": "時長",+ "originalDuration": "原始時長",+ "trimRange": "裁剪範圍",+ "duration": "最終時長","reset": "重設","apply": "套用","pickClipTitle": "選擇要編輯的片段",