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(transcript): let Ctrl/Cmd+Z in the transcript undo a cut
EtienneLescotef014f73977c
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsxindex 92ab665a7..8bdb078f9 100644--- a/src/components/ai-edition/RightPanes.tsx+++ b/src/components/ai-edition/RightPanes.tsx@@ -1474,6 +1474,9 @@ const TranscriptClipBlock = memo(function TranscriptClipBlock({role="textbox"tabIndex={0}contentEditable={!busy}+ // Ctrl/Cmd+Z here undoes the document: the browser's text history never sees+ // a transcript edit (see `undo.ts`).+ data-document-undo="true"aria-busy={busy}aria-readonly={busy}suppressContentEditableWarningdiff --git a/src/components/ai-edition/TranscriptPane.restore.test.tsx b/src/components/ai-edition/TranscriptPane.restore.test.tsxindex 6b7ffa24f..5afd738d4 100644--- a/src/components/ai-edition/TranscriptPane.restore.test.tsx+++ b/src/components/ai-edition/TranscriptPane.restore.test.tsx@@ -7,19 +7,26 @@// its line it wrapped to the start of the next one: getting there meant leaving the word,// and leaving the word took the bin away. jsdom has no layout, so these tests pin what keeps// the bin beside the word (out of the flow, inside the hovered word) and the gesture itself.+//+// Ctrl/Cmd+Z is the other way back, and the transcript used to hand it to the browser's text+// undo, where a cut never lands.import "@testing-library/jest-dom";-import { cleanup, fireEvent, render } from "@testing-library/react";+import { act, cleanup, fireEvent, render } from "@testing-library/react";import { useState } from "react";-import { afterEach, describe, expect, it, vi } from "vitest";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { I18nProvider } from "@/contexts/I18nContext";-import type {- AxcutAsset,- AxcutClip,- AxcutTranscript,- AxcutTrimRange,- AxcutWord,+import {+ type AxcutAsset,+ type AxcutClip,+ type AxcutTranscript,+ type AxcutTrimRange,+ type AxcutWord,+ createEmptyDocument,} from "@/lib/ai-edition/schema";+import { useProjectStore } from "@/lib/ai-edition/store/projectStore";+import { clearHistory, useUndoRedoShortcuts } from "@/lib/ai-edition/store/undo";+import { pushHistory } from "@/lib/ai-edition/store/undoStack";import { TranscriptPane } from "./RightPanes";vi.mock("@/native/client", () => ({ nativeBridgeClient: { aiEdition: {} } }));@@ -166,3 +173,58 @@ describe("restoring a cut word with the mouse", () => {expect(view.onRemoveTrimRanges).not.toHaveBeenCalled();});});++describe("restoring a cut word with Ctrl/Cmd+Z in the transcript", () => {+ const PROJECT_ID = "project_1";+ const empty = createEmptyDocument({ projectId: PROJECT_ID, title: "t" });+ const cut = { ...empty, timeline: { ...empty.timeline, trimRanges: [CUT] } };++ beforeEach(() => {+ useProjectStore.getState().clear();+ clearHistory();+ // The Backspace that made the cut, as the store records it.+ pushHistory({ projectId: PROJECT_ID, doc: empty });+ useProjectStore.setState({ projectId: PROJECT_ID, document: cut });+ });++ // The shell's wiring: the trims come from the document, undo walks the document.+ function renderFromStore() {+ let undoHandlers: ReturnType<typeof useUndoRedoShortcuts> | undefined;+ function Harness() {+ undoHandlers = useUndoRedoShortcuts(() => undefined);+ const trims = useProjectStore((s) => s.document?.timeline.trimRanges ?? []);+ return <Pane trimRanges={trims} onRemoveTrimRanges={vi.fn()} />;+ }+ const view = render(+ <I18nProvider>+ <Harness />+ </I18nProvider>,+ );+ const editor = view.getByRole("textbox");+ // jsdom does not implement `isContentEditable`; a browser reports it for the block,+ // and it is what used to hand the shortcut to the browser's text undo, which never+ // sees a transcript edit.+ Object.defineProperty(editor, "isContentEditable", { value: true });+ editor.focus();+ if (!undoHandlers) throw new Error("undo handlers not mounted");+ return { ...view, editor, runUndo: undoHandlers.runUndo };+ }++ it("undoes the cut from the keyboard (Windows and Linux)", () => {+ const view = renderFromStore();+ expect(wordEl(view.container, "w2")).toHaveAttribute("data-skip-id", "trim_1");++ fireEvent.keyDown(view.editor, { key: "z", ctrlKey: true });++ expect(wordEl(view.container, "w2")).not.toHaveAttribute("data-skip-id");+ });++ it("undoes the cut from the Edit menu, Cmd+Z's only route on macOS", () => {+ const view = renderFromStore();+ expect(window.document.activeElement).toBe(view.editor);++ act(() => view.runUndo());++ expect(wordEl(view.container, "w2")).not.toHaveAttribute("data-skip-id");+ });+});diff --git a/src/lib/ai-edition/store/undo.ts b/src/lib/ai-edition/store/undo.tsindex bc70ea53b..50b12007c 100644--- a/src/lib/ai-edition/store/undo.ts+++ b/src/lib/ai-edition/store/undo.ts@@ -75,10 +75,18 @@ export function redo(): boolean {* browser's own text undo is the one the user means. The keydown path checks the* event target, the menu path checks `activeElement` — same rule, two entry* points, so it lives in one function.+ *+ * A block marked `data-document-undo` is editable without being a text field: the+ * transcript is contentEditable only to carry a caret, and its edits are document+ * writes (Backspace is a trim) that the browser's text history never sees. Left to+ * that history, Ctrl/Cmd+Z there did nothing at all (#1012). The fields inside it+ * (the word editor) are still fields.*/function isTextEditingTarget(node: EventTarget | null): boolean {if (node instanceof HTMLTextAreaElement || node instanceof HTMLInputElement) return true;- return node instanceof HTMLElement && node.isContentEditable;+ return (+ node instanceof HTMLElement && node.isContentEditable && !node.closest("[data-document-undo]")+ );}export interface UndoRedoHandlers {