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
fix(editor): hide the cursor settings when a take has no cursor data
EtienneLescota4e1fd01e6da
diff --git a/src/components/ai-edition/recordedCursorTypes.ts b/src/components/ai-edition/recordedCursorTypes.tsindex b11ecdbcc..80aa4e5a4 100644--- a/src/components/ai-edition/recordedCursorTypes.ts+++ b/src/components/ai-edition/recordedCursorTypes.ts@@ -44,13 +44,20 @@ export function cursorStatesBetween(// A recording's cursor file does not change once written: each is read once per session. A// recording without one reads as empty, and that answer is kept.const changesByPath = new Map<string, Promise<CursorStateChange[]>>();+// What each of those answered once it did: whether the recording has any cursor data at all. Kept+// beside the promises so a hook mounted again renders the answer at once, not a frame later.+const hasCursorByPath = new Map<string, boolean>();function stateChangesOf(videoPath: string): Promise<CursorStateChange[]> {let changes = changesByPath.get(videoPath);if (!changes) {changes = Promise.resolve().then(() => nativeBridgeClient.cursor.getRecordingData(videoPath))- .then((data) => cursorStateChanges(data.samples))+ .then((data) => {+ const read = cursorStateChanges(data.samples);+ hasCursorByPath.set(videoPath, read.length > 0);+ return read;+ })// A read that failed (no bridge yet, a file still being written) shows nothing but the// arrow for now, and is tried again the next time rather than never..catch(() => {@@ -77,6 +84,36 @@ function clipSourceRanges(document: AxcutDocument | null): Array<[string, number});}+/** Whether one of `paths` has cursor data: `null` while some are still unread and none has any. */+function cursorDataIn(paths: readonly string[]): boolean | null {+ if (paths.some((path) => hasCursorByPath.get(path))) return true;+ return paths.every((path) => hasCursorByPath.has(path)) ? false : null;+}++/**+ * Whether any recording the timeline plays has cursor data, or `null` while they are read. A take+ * recorded with the system cursor has it baked into the pixels and no cursor file, so every cursor+ * setting would change nothing: the editor leaves them out.+ */+export function useHasRecordedCursor(): boolean | null {+ // A string, so the recordings are read again when one is swapped, not on every other edit.+ const pathsJson = useProjectStore((s) =>+ JSON.stringify([...new Set(clipSourceRanges(s.document).map(([path]) => path))]),+ );+ const [has, setHas] = useState(() => cursorDataIn(JSON.parse(pathsJson)));+ useEffect(() => {+ let cancelled = false;+ const paths = JSON.parse(pathsJson) as string[];+ void Promise.all(paths.map(stateChangesOf)).then(() => {+ if (!cancelled) setHas(cursorDataIn(paths));+ });+ return () => {+ cancelled = true;+ };+ }, [pathsJson]);+ return has;+}+/*** Every cursor state the timeline's clips put on screen, or `null` while their recordings are* read. The cursor pane offers to redraw these and nothing else: a choice about a cursor thediff --git a/src/components/ai-edition/v4/FloatingInspector.test.tsx b/src/components/ai-edition/v4/FloatingInspector.test.tsxindex 422cfabf3..0c5078462 100644--- a/src/components/ai-edition/v4/FloatingInspector.test.tsx+++ b/src/components/ai-edition/v4/FloatingInspector.test.tsx@@ -1,8 +1,10 @@// @vitest-environment jsdomimport "@testing-library/jest-dom";-import { fireEvent, render, screen, within } from "@testing-library/react";+import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";import { afterEach, describe, expect, it, vi } from "vitest";+import { assetSchema, clipSchema, createEmptyDocument } from "@/lib/ai-edition/schema";import { useProjectStore } from "@/lib/ai-edition/store/projectStore";+import { nativeBridgeClient } from "@/native";vi.mock("@/contexts/I18nContext", () => ({useScopedT: (scope: string) => (key: string) => `${scope}.${key}`,@@ -273,6 +275,110 @@ describe("FloatingInspector", () => {}});});++ describe("cursor facet", () => {+ const cursorFacet = () => screen.queryByRole("button", { name: "settings.cursor.title" });++ /** One clip per recording, each recording's cursor file holding that many samples. */+ function openProject(...sampleCounts: number[]) {+ // A path per test: every recording is read once per session.+ const run = crypto.randomUUID();+ const samplesOf = new Map<string, number>();+ const assets = sampleCounts.map((count, i) => {+ const originalPath = `/recordings/${run}-${i}.mp4`;+ samplesOf.set(originalPath, count);+ return assetSchema.parse({ id: `a${i}`, label: "take", originalPath });+ });+ const clips = assets.map((asset, i) =>+ clipSchema.parse({+ id: `c${i}`,+ assetId: asset.id,+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: i * 10,+ timelineEndSec: i * 10 + 10,+ origin: "user",+ }),+ );+ const read = vi+ .spyOn(nativeBridgeClient.cursor, "getRecordingData")+ .mockImplementation(async (videoPath) => ({+ version: 2,+ provider: "native",+ assets: [],+ samples: Array.from({ length: samplesOf.get(videoPath ?? "") ?? 0 }, (_, i) => ({+ timeMs: i * 100,+ cx: 0.5,+ cy: 0.5,+ })),+ }));+ const document = createEmptyDocument({ projectId: "p", title: "t" });+ useProjectStore.setState({+ projectId: "p",+ document: { ...document, assets, timeline: { ...document.timeline, clips } },+ });+ return read;+ }++ /** Lets the recordings' cursor files be read, so an absence is an answer and not a wait. */+ async function readAll(read: ReturnType<typeof openProject>) {+ await waitFor(() => expect(read).toHaveBeenCalled());+ await act(async () => {+ await Promise.all(read.mock.results.map((r) => r.value));+ });+ }++ afterEach(() => {+ vi.restoreAllMocks();+ useProjectStore.setState({ document: null });+ });++ it("is offered when a recording on the timeline has cursor data", async () => {+ openProject(3);+ render(<FloatingInspector {...defaultProps} />);+ expect(await screen.findByRole("button", { name: "settings.cursor.title" })).toBeVisible();+ });++ // A system-cursor take has the cursor baked into its pixels and no cursor file.+ it("is left out for a take with no cursor data", async () => {+ const read = openProject(0);+ render(<FloatingInspector {...defaultProps} />);+ await readAll(read);+ expect(cursorFacet()).toBeNull();+ expect(screen.getByRole("button", { name: "settings.layout.title" })).toBeVisible();+ });++ it("is offered as soon as one of several recordings has cursor data", async () => {+ openProject(0, 2);+ render(<FloatingInspector {...defaultProps} />);+ expect(await screen.findByRole("button", { name: "settings.cursor.title" })).toBeVisible();+ });++ it("is left out with nothing on the timeline", async () => {+ render(<FloatingInspector {...defaultProps} />);+ await act(() => Promise.resolve());+ expect(cursorFacet()).toBeNull();+ });++ it("falls back to the first facet when the chosen one is left out", async () => {+ const read = openProject(0);+ render(<FloatingInspector {...defaultProps} facet="cursor" />);+ await readAll(read);+ expect(screen.getByTestId("effects-pane")).toBeInTheDocument();+ expect(screen.queryByTestId("cursor-pane")).toBeNull();+ expect(screen.getByRole("button", { name: "settings.effects.title" })).toHaveAttribute(+ "aria-pressed",+ "true",+ );+ });++ it("shows the cursor pane once the chosen facet has data", async () => {+ openProject(3);+ render(<FloatingInspector {...defaultProps} facet="cursor" />);+ expect(await screen.findByTestId("cursor-pane")).toBeInTheDocument();+ expect(cursorFacet()).toHaveAttribute("aria-pressed", "true");+ });+ });});describe("AnnotationSizeField", () => {diff --git a/src/components/ai-edition/v4/FloatingInspector.tsx b/src/components/ai-edition/v4/FloatingInspector.tsxindex eb87497e3..166e382ef 100644--- a/src/components/ai-edition/v4/FloatingInspector.tsx+++ b/src/components/ai-edition/v4/FloatingInspector.tsx@@ -73,6 +73,7 @@ import {TranscriptPane,VideoEffectsPane,} from "../RightPanes";+import { useHasRecordedCursor } from "../recordedCursorTypes";import { TextColorField } from "../TextColorField";import styles from "./EditorShellV4.module.css";@@ -116,7 +117,7 @@ interface FloatingInspectorProps {}export function FloatingInspector({- facet,+ facet: chosenFacet,open,onFacetChange,onToggleOpen,@@ -127,6 +128,12 @@ export function FloatingInspector({}: FloatingInspectorProps) {const ts = useScopedT("settings");const te = useScopedT("editor");+ // A take with no cursor data (recorded with the system cursor, or imported) has nothing for+ // the cursor settings to act on, so that facet is not offered: never shown while the answer is+ // unknown, and a choice of it that lost its footing falls back to the first facet.+ const hasCursor = useHasRecordedCursor() === true;+ const facets = hasCursor ? FACETS : FACETS.filter(({ id }) => id !== "cursor");+ const facet = facets.some(({ id }) => id === chosenFacet) ? chosenFacet : facets[0].id;const [clipPickerOpen, setClipPickerOpen] = useState(false);const clipPickerRef = useRef<HTMLDivElement | null>(null);useEffect(() => {@@ -158,7 +165,7 @@ export function FloatingInspector({</div>) : null}<div className={styles.facetRail}>- {FACETS.map(({ id, labelKey, icon: Icon }) => (+ {facets.map(({ id, labelKey, icon: Icon }) => (<buttonkey={id}type="button"diff --git a/technical-documentation/testing/manual-e2e-checklist.md b/technical-documentation/testing/manual-e2e-checklist.mdindex b9347793d..7404054d9 100644--- a/technical-documentation/testing/manual-e2e-checklist.md+++ b/technical-documentation/testing/manual-e2e-checklist.md@@ -576,7 +576,7 @@ The percentage is computed in the renderer against a predicted frame total, and## Settings, shortcuts, themes, i18n-The inspector's rail holds five facets: Composition (background, format, frame, motion), Camera layout, Audio, Cursor, and Transcript, whose *Captions* button opens the caption settings.+The inspector's rail holds five facets: Composition (background, format, frame, motion), Camera layout, Audio, Cursor (only while a recording on the timeline has cursor data), and Transcript, whose *Captions* button opens the caption settings.- [ ] Open OpenScreen menu → *Keyboard Shortcuts*, change one shortcut, save it, use the new key in the editor, and confirm it triggers the configured action.- [ ] Confirm `Ctrl/Cmd+S` saves the current project with a "Project saved" toast.@@ -596,6 +596,7 @@ The inspector's rail holds five facets: Composition (background, format, frame,- [ ] Open the Cursor facet and toggle *Show cursor* and *Auto-hide when inactive*; confirm the preview changes.- [ ] Change *Size*, *Smoothing* and *Motion blur*, pick each *Click bounce* (None, Light, Strong), and toggle *Click impact*; confirm each committed value remains visible.- [ ] Pick each *Cursor style* and toggle *3D cursor*; confirm the preview cursor changes. Under *Cursor types*, switch a type off and confirm that type is drawn as the arrow.+- [ ] Record a take with *Cursor highlight* Off (the system cursor), open it in the editor, and confirm the rail has no Cursor facet; confirm a take recorded with it On shows the facet, and an imported video does not.- [ ] Open OpenScreen menu → *Switch to light theme* (or dark) and confirm the editor switches between dark and light themes.- [ ] Open OpenScreen menu → *Change language*, choose a non-English locale, and confirm visible UI strings change.- [ ] Switch back to English and confirm the top bar, transport, inspector, and export labels return to English.