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): a free speed field beyond 3x, and zoom focus that can follow the cursor
Etienne Lescot5a525320c09b
diff --git a/src/components/ai-edition/v4/FloatingInspector.tsx b/src/components/ai-edition/v4/FloatingInspector.tsxindex 4910562c5..d13874101 100644--- a/src/components/ai-edition/v4/FloatingInspector.tsx+++ b/src/components/ai-edition/v4/FloatingInspector.tsx@@ -15,6 +15,13 @@ import {} from "lucide-react";import type { ComponentProps } from "react";import { useState } from "react";+import { toast } from "sonner";+import { parseCustomPlaybackSpeedInput } from "@/components/video-editor/customPlaybackSpeed";+import {+ MAX_NATIVE_PLAYBACK_RATE,+ MAX_PLAYBACK_SPEED,+ SPEED_OPTIONS,+} from "@/components/video-editor/types";import { useScopedT } from "@/contexts/I18nContext";import type { AxcutClip } from "@/lib/ai-edition/schema";import type { useTimeline } from "@/lib/ai-edition/store/useTimeline";@@ -272,7 +279,90 @@ function paneRow(label: string, control: React.ReactNode) {}const ZOOM_DEPTHS = [1, 2, 3, 4, 5, 6] as const;-const SPEED_VALUES = [0.5, 0.75, 1, 1.25, 1.5, 2, 3];+// The ladder the shared editor already ships (`SPEED_OPTIONS`), plus 1× so the select can+// express "back to normal". It stops at 5×; the free field in `SpeedControl` is what reaches+// `MAX_PLAYBACK_SPEED`.+const SPEED_PRESETS = [1, ...SPEED_OPTIONS.map((option) => option.speed)].sort((a, b) => a - b);++/**+ * Preset select + free numeric field, the speed UX this editor already had translations for+ * (`settings.speed.customPlaybackSpeed` / `maxSpeedError` / `previewFrameSteppingHint`, shipped+ * in all 13 locales) but no longer any control for: the V4 shell replaced the panel that hosted+ * it with a preset-only `<select>` capped at 3×, while the underlying capability goes to+ * `MAX_PLAYBACK_SPEED` (100×). Only the control was missing, so this rewires it rather than+ * adding anything new.+ */+export function SpeedControl({+ region,+ tl,+}: {+ region: { id: string; speed: number };+ tl: Pick<TimelineApi, "updateSpeedValue">;+}) {+ const ts = useScopedT("settings");+ // "" means the field is idle and the select is showing the truth. A non-empty draft is+ // uncommitted text; it's cleared on commit so the placeholder tracks the live speed again.+ const [draft, setDraft] = useState("");++ const commitDraft = () => {+ const result = parseCustomPlaybackSpeedInput(draft);+ if (result.status === "valid") {+ void tl.updateSpeedValue(region.id, result.speed);+ } else if (result.status === "too-fast") {+ toast.error(ts("speed.maxSpeedError", { max: MAX_PLAYBACK_SPEED }));+ }+ // Anything else (empty, unparseable, below the floor) just reverts to the live value+ // rather than guessing at an intent.+ setDraft("");+ };++ // A custom speed matches no preset, so surface it as its own option — otherwise the select+ // would fall back to rendering its first entry and misreport the region.+ const options = SPEED_PRESETS.includes(region.speed)+ ? SPEED_PRESETS+ : [...SPEED_PRESETS, region.speed].sort((a, b) => a - b);++ return (+ <>+ {paneRow(+ ts("speed.playbackSpeed"),+ <select+ value={region.speed}+ onChange={(e) => void tl.updateSpeedValue(region.id, Number(e.target.value))}+ style={selectStyle}+ >+ {options.map((speed) => (+ <option key={speed} value={speed}>+ {speed}×+ </option>+ ))}+ </select>,+ )}+ {paneRow(+ ts("speed.customPlaybackSpeed"),+ <input+ type="text"+ inputMode="decimal"+ placeholder={`${region.speed}×`}+ value={draft}+ onChange={(e) => setDraft(e.target.value)}+ onBlur={commitDraft}+ // Enter blurs, and the blur handler commits — one path, so a keyboard commit+ // can't apply the same draft twice.+ onKeyDown={(e) => {+ if (e.key === "Enter") e.currentTarget.blur();+ }}+ style={{ ...selectStyle, width: 84, textAlign: "right" }}+ />,+ )}+ {region.speed > MAX_NATIVE_PLAYBACK_RATE ? (+ <p style={{ margin: 0, font: "400 11px/1.45 var(--font-sans)", color: "var(--fg-2)" }}>+ {ts("speed.previewFrameSteppingHint", { native: MAX_NATIVE_PLAYBACK_RATE })}+ </p>+ ) : null}+ </>+ );+}function SelectionPane({ tl, onClose }: { tl: TimelineApi; onClose: () => void }) {const ts = useScopedT("settings");@@ -330,16 +420,38 @@ function SelectionPane({ tl, onClose }: { tl: TimelineApi; onClose: () => void }))}</select>,)}- <button- type="button"- onClick={() => {- tl.updateZoomFocusLive(region.id, { cx: 0.5, cy: 0.5 });- void tl.commitZoomFocus();- }}- style={secondaryBtnStyle}- >- {te("inspector.resetFocusPoint")}- </button>+ {paneRow(+ ts("zoom.focusMode.title"),+ <select+ value={region.focusMode ?? "manual"}+ onChange={(e) =>+ void tl.updateZoomFocusMode(region.id, e.target.value as "manual" | "auto")+ }+ style={selectStyle}+ >+ <option value="manual">{ts("zoom.focusMode.manual")}</option>+ <option value="auto">{ts("zoom.focusMode.auto")}</option>+ </select>,+ )}+ {region.focusMode === "auto" ? (+ // In auto the focus is resampled from cursor telemetry every frame, so there is+ // no fixed point to reset and no gimbal on the canvas (ZoomFocusOverlay bows out+ // for auto regions). Offering the reset button here would offer a no-op.+ <p style={{ margin: 0, font: "400 11px/1.45 var(--font-sans)", color: "var(--fg-2)" }}>+ {ts("zoom.focusMode.autoDescription")}+ </p>+ ) : (+ <button+ type="button"+ onClick={() => {+ tl.updateZoomFocusLive(region.id, { cx: 0.5, cy: 0.5 });+ void tl.commitZoomFocus();+ }}+ style={secondaryBtnStyle}+ >+ {te("inspector.resetFocusPoint")}+ </button>+ )}<button type="button" onClick={deleteAndClose} style={deleteBtnStyle}><Trash2 size={14} />{ts("zoom.deleteZoom")}@@ -356,20 +468,7 @@ function SelectionPane({ tl, onClose }: { tl: TimelineApi; onClose: () => void }<div style={{ display: "flex", flexDirection: "column", minHeight: 0 }}>{paneHeader(<ZoomIn size={15} />, tt("labels.speed"), onClose, tc("actions.close"))}<div style={bodyStyle}>- {paneRow(- ts("speed.playbackSpeed"),- <select- value={region.speed}- onChange={(e) => void tl.updateSpeedValue(region.id, Number(e.target.value))}- style={selectStyle}- >- {SPEED_VALUES.map((s) => (- <option key={s} value={s}>- {s}×- </option>- ))}- </select>,- )}+ <SpeedControl region={region} tl={tl} /><button type="button" onClick={deleteAndClose} style={deleteBtnStyle}><Trash2 size={14} />{ts("speed.deleteRegion")}diff --git a/src/components/ai-edition/v4/SpeedControl.test.tsx b/src/components/ai-edition/v4/SpeedControl.test.tsxnew file mode 100644index 000000000..8fc858763--- /dev/null+++ b/src/components/ai-edition/v4/SpeedControl.test.tsx@@ -0,0 +1,92 @@+import "@testing-library/jest-dom";+import { fireEvent, render, screen } from "@testing-library/react";+import { beforeEach, describe, expect, it, vi } from "vitest";++// The pane is only reachable with a project open and a speed region selected, so drive the+// control directly. Both collaborators are stubbed: the translator echoes keys (assertions read+// better against a key than against prose that changes with copy edits), and `sonner` records the+// error toast without needing a mounted <Toaster>.+vi.mock("@/contexts/I18nContext", () => ({+ useScopedT: () => (key: string, vars?: Record<string, unknown>) =>+ vars ? `${key}:${Object.values(vars).join(",")}` : key,+}));++const toastError = vi.fn();+vi.mock("sonner", () => ({ toast: { error: (message: string) => toastError(message) } }));++import { SpeedControl } from "./FloatingInspector";++function renderControl(speed: number) {+ const updateSpeedValue = vi.fn(async () => {+ // the control only awaits the promise, never its value+ });+ render(<SpeedControl region={{ id: "sp1", speed }} tl={{ updateSpeedValue }} />);+ const field = screen.getByPlaceholderText(`${speed}×`);+ return { updateSpeedValue, field };+}++describe("SpeedControl", () => {+ beforeEach(() => {+ toastError.mockClear();+ });++ it("commits a free-typed speed above the preset ceiling", () => {+ // The regression this control exists for: the V4 shell only offered presets up to 3×,+ // while the underlying capability reaches 100×.+ const { updateSpeedValue, field } = renderControl(1);+ fireEvent.change(field, { target: { value: "25" } });+ fireEvent.blur(field);+ expect(updateSpeedValue).toHaveBeenCalledWith("sp1", 25);+ });++ it("commits on Enter as well as on blur, and only once", () => {+ const { updateSpeedValue, field } = renderControl(1);+ fireEvent.change(field, { target: { value: "7.5" } });+ fireEvent.keyDown(field, { key: "Enter" });+ fireEvent.blur(field);+ expect(updateSpeedValue).toHaveBeenCalledTimes(1);+ expect(updateSpeedValue).toHaveBeenCalledWith("sp1", 7.5);+ });++ it("refuses a speed past the maximum and says so", () => {+ const { updateSpeedValue, field } = renderControl(1);+ fireEvent.change(field, { target: { value: "500" } });+ fireEvent.blur(field);+ expect(updateSpeedValue).not.toHaveBeenCalled();+ expect(toastError).toHaveBeenCalledWith("speed.maxSpeedError:100");+ });++ it("ignores an unparseable draft without touching the region", () => {+ const { updateSpeedValue, field } = renderControl(2);+ fireEvent.change(field, { target: { value: "abc" } });+ fireEvent.blur(field);+ expect(updateSpeedValue).not.toHaveBeenCalled();+ expect(toastError).not.toHaveBeenCalled();+ });++ it("clears the draft after a commit so the placeholder tracks the live speed", () => {+ const { field } = renderControl(1);+ fireEvent.change(field, { target: { value: "4" } });+ fireEvent.blur(field);+ expect(field).toHaveValue("");+ });++ it("surfaces a custom speed as its own option instead of misreporting a preset", () => {+ // 25× matches no preset. Without an injected <option> the select would fall back to+ // rendering its first entry, telling the user the region runs at 0.25×.+ renderControl(25);+ const select = screen.getByRole("combobox") as HTMLSelectElement;+ expect(select.value).toBe("25");+ expect(Array.from(select.options).map((o) => o.value)).toContain("25");+ });++ it("warns that preview frame-steps above the native playback rate", () => {+ renderControl(25);+ expect(screen.getByText("speed.previewFrameSteppingHint:16")).toBeInTheDocument();+ });++ it("stays quiet about frame-stepping at a natively playable speed", () => {+ renderControl(2);+ expect(screen.queryByText(/previewFrameSteppingHint/)).not.toBeInTheDocument();+ });+});diff --git a/src/lib/ai-edition/store/useTimeline.ts b/src/lib/ai-edition/store/useTimeline.tsindex 6733295b4..907622606 100644--- a/src/lib/ai-edition/store/useTimeline.ts+++ b/src/lib/ai-edition/store/useTimeline.ts@@ -495,6 +495,28 @@ export function useTimeline() {[document, saveDocument],);+ // Nothing could set `focusMode`: "auto" only ever arrived from the automatic suggestion pass+ // (`zoomSuggestions.ts`), so a hand-drawn zoom stayed pinned to its static focus point with no+ // way to make it follow the cursor. The capability itself was complete end to end —+ // `sceneDescription.ts` ships the mode, `scene.rs` parses it, `regions.rs::resolve_focus`+ // samples the cursor track — only this setter was missing.+ //+ // Writing "manual" explicitly is safe even though `migrate.ts` only persists "auto": an absent+ // field MEANS manual, so both forms resolve identically.+ const updateZoomFocusMode = useCallback(+ async (id: string, focusMode: "manual" | "auto") => {+ if (!document) return;+ const next: AxcutDocument = {+ ...document,+ zoomRanges: patchPillById(document.zoomRanges, id, {+ focusMode,+ }) as AxcutDocument["zoomRanges"],+ };+ await saveDocument(next);+ },+ [document, saveDocument],+ );+const updateAnnotationSpan = useCallback(async (id: string, startMs: number, endMs: number) => {if (!document) return;@@ -1139,6 +1161,7 @@ export function useTimeline() {updateZoomFocusLive,commitZoomFocus,updateZoomDepth,+ updateZoomFocusMode,updateAnnotationSpan,updateAnnotationLive,commitAnnotationChange,