Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(zoom): step over disabled levels by keyboard, and limit a zoom by every clip it spans

EtienneLescot68b5c3d08bea
diff --git a/src/components/ai-edition/ChoiceRow.test.tsx b/src/components/ai-edition/ChoiceRow.test.tsx
new file mode 100644
index 000000000..f5aa7e969
--- /dev/null
+++ b/src/components/ai-edition/ChoiceRow.test.tsx
@@ -0,0 +1,45 @@
+// @vitest-environment jsdom
+// Arrow keys step over holes and disabled options in the direction of travel, so an enabled
+// option past them stays reachable from the keyboard.
+
+import "@testing-library/jest-dom";
+import { fireEvent, render, screen } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+
+vi.mock("sonner", () => ({ toast: { error: vi.fn(), success: vi.fn(), info: vi.fn() } }));
+
+import { ChoiceRow } from "./RightPanes";
+
+describe("ChoiceRow keyboard", () => {
+ it("skips disabled options and holes, both ways, and stops at the ends", () => {
+ const onChange = vi.fn();
+ render(
+ <ChoiceRow<number>
+ label="row"
+ value={1}
+ onChange={onChange}
+ options={[
+ { value: 1, label: "one" },
+ { value: 2, label: "two", disabled: true },
+ null,
+ { value: 3, label: "three", disabled: true },
+ { value: 4, label: "four" },
+ ]}
+ />,
+ );
+ const group = screen.getByRole("group", { name: "row" });
+ fireEvent.keyDown(group, { key: "ArrowRight" });
+ expect(onChange).toHaveBeenLastCalledWith(4);
+ expect(screen.getByRole("button", { name: "four" })).toHaveFocus();
+
+ // The row is not re-rendered with 4 here, so going back to 1 is a re-press: focus only.
+ fireEvent.keyDown(group, { key: "ArrowLeft" });
+ expect(screen.getByRole("button", { name: "one" })).toHaveFocus();
+
+ // Nothing enabled before the first option: stay put.
+ onChange.mockClear();
+ fireEvent.keyDown(group, { key: "ArrowLeft" });
+ expect(onChange).not.toHaveBeenCalled();
+ expect(screen.getByRole("button", { name: "one" })).toHaveFocus();
+ });
+});
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index 65258360b..35a0bfce8 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -4010,10 +4010,13 @@ export function ChoiceRow<T extends string | number>({
e.nativeEvent.stopPropagation();
const focused = buttonsRef.current.findIndex((b) => b === document.activeElement);
const from = focused >= 0 ? focused : options.findIndex((o) => o?.value === value);
- // A hole is stepped over, not landed on.
- const to = options[from + step] === null ? from + 2 * step : from + step;
+ // Holes and disabled options are stepped over, not landed on.
+ let to = from + step;
+ while (to >= 0 && to < options.length && (options[to] ?? { disabled: true }).disabled) {
+ to += step;
+ }
const next = options[to];
- if (!next || next.disabled) return;
+ if (!next) return;
buttonsRef.current[to]?.focus();
if (next.value !== value) onChange(next.value);
}}
diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.ts
index 004dabf69..d1790e10a 100644
--- a/src/native/sceneDescription.test.ts
+++ b/src/native/sceneDescription.test.ts
@@ -627,6 +627,50 @@ describe("buildSceneDescription.zoomRegions", () => {
});
});
+ it("limits a zoom straddling two clips by the tighter of the two", () => {
+ const video = (width: number, height: number) => ({ codec: "h264", width, height, fps: 30 });
+ const doc = makeDoc({
+ assets: [
+ makeAsset({
+ id: "uhd",
+ originalPath: "/uhd.mp4",
+ durationSec: 5,
+ video: video(3840, 2160),
+ }),
+ makeAsset({ id: "hd", originalPath: "/hd.mp4", durationSec: 5, video: video(1920, 1080) }),
+ ],
+ clips: [
+ makeClip({
+ id: "c1",
+ assetId: "uhd",
+ sourceStartSec: 0,
+ sourceEndSec: 5,
+ timelineStartSec: 0,
+ timelineEndSec: 5,
+ }),
+ makeClip({
+ id: "c2",
+ assetId: "hd",
+ sourceStartSec: 0,
+ sourceEndSec: 5,
+ timelineStartSec: 5,
+ timelineEndSec: 10,
+ }),
+ ],
+ // Starts on the 2160p clip (limit 5×) and ends on the 1080p one (limit 2.5×).
+ zoomRanges: [
+ makeZoom({ id: "z", startMs: 3000, endMs: 7000, depth: 6, focus: { cx: 0.5, cy: 0.5 } }),
+ ],
+ legacyEditor: { padding: 50, aspectRatio: "16:9" },
+ });
+ const pieces = buildSceneDescription(doc).zoomRegions;
+ expect(pieces.map((z) => [z.clipIndex, z.scale])).toEqual([
+ [0, 5],
+ [1, 2.5],
+ ]);
+ expect(zoomScaleLimit(doc, "z")).toBe(2.5);
+ });
+
it("customScale overrides the depth-derived value", () => {
const z = makeZoom({
id: "z",
diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.ts
index 25f19fab6..75bbd8139 100644
--- a/src/native/sceneDescription.ts
+++ b/src/native/sceneDescription.ts
@@ -658,16 +658,28 @@ function zoomScaleLimitOf(
* is not on screen.
*/
export function zoomScaleLimit(document: AxcutDocument, regionId: string): number {
+ const region = (document.zoomRanges ?? []).find((z) => z.id === regionId);
+ if (!region) return MAX_ZOOM_SCALE;
const scene = buildSceneDescription(document);
- const clipIndex = scene.zoomRegions.find((z) => z.id === regionId)?.clipIndex ?? 0;
- const clip = resolveVisibleClips(document)[clipIndex];
- if (!clip) return MAX_ZOOM_SCALE;
- const video = document.assets.find((a) => a.id === clip.assetId)?.video;
- return zoomScaleLimitOf(
- scene.layout.layoutByClip?.[clipIndex]?.screenRect ?? scene.layout.screenRect ?? null,
- scene.output,
- screenSourceSize(video, scene.cropByClip[clipIndex]),
- );
+ const visibleClips = resolveVisibleClips(document);
+ // A region straddling a cut becomes one piece per clip, each with its own id: the same
+ // projection as the scene, and the tightest of their limits.
+ const pieces = projectRegionsToSource([region], visibleClips, document.timeline.clips, () => "");
+ let limit = MAX_ZOOM_SCALE;
+ for (const { clipIndex = 0 } of pieces) {
+ const clip = visibleClips[clipIndex];
+ if (!clip) continue;
+ const video = document.assets.find((a) => a.id === clip.assetId)?.video;
+ limit = Math.min(
+ limit,
+ zoomScaleLimitOf(
+ scene.layout.layoutByClip?.[clipIndex]?.screenRect ?? scene.layout.screenRect ?? null,
+ scene.output,
+ screenSourceSize(video, scene.cropByClip[clipIndex]),
+ ),
+ );
+ }
+ return limit;
}
/** Serialize a document into a {@link SceneDescription}. Pure — no per-frame math. */