Skip to content

Write HTML. Render video. Built for agents.

feat(studio): move undo and redo into the timeline toolbar (#4196)

Miguel Ángelf9fc55218880
diff --git a/packages/studio/src/components/StudioHeader.dom.test.tsx b/packages/studio/src/components/StudioHeader.dom.test.tsx
index 18dc32ca4e..b6d79f1939 100644
--- a/packages/studio/src/components/StudioHeader.dom.test.tsx
+++ b/packages/studio/src/components/StudioHeader.dom.test.tsx
@@ -1,7 +1,7 @@
// @vitest-environment happy-dom
/**
- * The header on the shared primitives: same controls, disabled history still explained,
+ * The header on the shared primitives: Capture and Inspector grouped, Export separate,
* hotkey filters unchanged (KTD13). Contexts are mocked, not provided.
*/
import React, { act } from "react";
@@ -61,7 +61,7 @@ afterEach(() => {
host.remove();
});
-function mount(): HTMLElement {
+function mount(props: { inspectorButtonActive?: boolean } = {}): HTMLElement {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
@@ -73,7 +73,7 @@ function mount(): HTMLElement {
captureFrameFilename="frame.png"
handleCaptureFrameClick={vi.fn()}
refreshCaptureFrameTime={vi.fn()}
- inspectorButtonActive={false}
+ inspectorButtonActive={props.inspectorButtonActive ?? false}
inspectorPanelActive={false}
/>,
),
@@ -107,19 +107,48 @@ it("renders Export as the shared primary Button at the medium size", () => {
);
});
-it("disables Undo and Redo while the history is empty", () => {
+it("no longer renders Undo or Redo in the header", () => {
const host = mount();
- expect(query(host, '[aria-label="Undo"]').hasAttribute("disabled")).toBe(true);
- expect(query(host, '[aria-label="Redo"]').hasAttribute("disabled")).toBe(true);
+ expect(host.querySelector('[aria-label="Undo"]')).toBeNull();
+ expect(host.querySelector('[aria-label="Redo"]')).toBeNull();
});
-it("enables Undo once there is something to undo", () => {
- editHistory.canUndo = true;
- editHistory.undoLabel = "Move layer";
+it("groups Capture and Inspector in one bordered segment, Export outside it", () => {
const host = mount();
+ const group = query(host, '[aria-label="Capture current frame"]').closest(".divide-x");
- expect(query(host, '[aria-label="Undo"]').hasAttribute("disabled")).toBe(false);
+ expect(group?.contains(query(host, '[aria-label="Inspector"]'))).toBe(true);
+ expect(group?.contains(query(host, '[data-testid="header-export"]'))).toBe(false);
+ expect(group).not.toBeNull();
+});
+
+it("drops the Capture label below 1000px but keeps its accessible name", () => {
+ const host = mount();
+ const capture = query(host, '[aria-label="Capture current frame"]');
+
+ expect(query(capture, "span").className).toContain("max-[1000px]:hidden");
+});
+
+/** The bare token, not a `hover:`/`data-[…]:`-prefixed variant of it. */
+function hasToken(className: string, token: string): boolean {
+ return className.split(/\s+/).includes(token);
+}
+
+it("shows Inspector pressed and filled only when on", () => {
+ const host = mount({ inspectorButtonActive: true });
+ const on = query(host, '[aria-label="Inspector"]');
+ expect(on.getAttribute("aria-pressed")).toBe("true");
+ expect(hasToken(on.className, "text-accent")).toBe(true);
+ expect(hasToken(on.className, "bg-hover")).toBe(true);
+ act(() => mounted?.root.unmount());
+ mounted?.host.remove();
+ mounted = null;
+
+ const off = query(mount(), '[aria-label="Inspector"]');
+ expect(off.getAttribute("aria-pressed")).toBe("false");
+ expect(hasToken(off.className, "text-accent")).toBe(false);
+ expect(hasToken(off.className, "bg-hover")).toBe(false);
});
it("keeps Capture a real download link rather than a button", () => {
@@ -130,7 +159,8 @@ it("keeps Capture a real download link rather than a button", () => {
expect(capture.tagName).toBe("A");
expect(capture.getAttribute("download")).toBe("frame.png");
- expectRecipe(capture, buttonSizes.md);
+ // h-full replaces the md height: the group's own h-ctl sets the shared control height.
+ expectRecipe(capture, "px-3", "text-step-12");
});
it("classifies the new header controls for the hotkey filters as the old ones were (KTD13)", () => {
@@ -140,8 +170,6 @@ it("classifies the new header controls for the hotkey filters as the old ones we
const host = mount();
const controls = [
query(host, '[data-testid="header-export"]'),
- query(host, '[aria-label="Undo"]'),
- query(host, '[aria-label="Redo"]'),
query(host, '[aria-label="Inspector"]'),
query(host, '[aria-label="Capture current frame"]'),
];
diff --git a/packages/studio/src/components/StudioHeader.test.ts b/packages/studio/src/components/StudioHeader.test.ts
index ff06512dca..4d897faa76 100644
--- a/packages/studio/src/components/StudioHeader.test.ts
+++ b/packages/studio/src/components/StudioHeader.test.ts
@@ -1,22 +1,5 @@
import { describe, expect, it } from "vitest";
-import { historyTooltipLabel, shouldOpenInspector } from "./StudioHeader";
-
-describe("historyTooltipLabel", () => {
- // A disabled control gets no pointer events, so its tooltip cannot be opened
- // to read. The wording is checked here instead of through the DOM.
- it("names the action that would be undone", () => {
- expect(historyTooltipLabel("undo", "Move layer")).toMatch(/^Undo Move layer \(.+\)$/);
- });
-
- it("names the action that would be redone", () => {
- expect(historyTooltipLabel("redo", "Move layer")).toMatch(/^Redo Move layer \(.+\)$/);
- });
-
- it("keeps the shortcut when the history is empty", () => {
- expect(historyTooltipLabel("undo", undefined)).toMatch(/^Undo \(.+\)$/);
- expect(historyTooltipLabel("redo", null)).toMatch(/^Redo \(.+\)$/);
- });
-});
+import { shouldOpenInspector } from "./StudioHeader";
describe("shouldOpenInspector", () => {
it("opens when the panel is hidden", () => {
diff --git a/packages/studio/src/components/StudioHeader.tsx b/packages/studio/src/components/StudioHeader.tsx
index 5b8633b3b5..7210df3845 100644
--- a/packages/studio/src/components/StudioHeader.tsx
+++ b/packages/studio/src/components/StudioHeader.tsx
@@ -1,10 +1,9 @@
import type { MouseEvent } from "react";
-import { RotateCcw, RotateCw, Camera } from "../icons/SystemIcons";
-import { getHistoryShortcutLabel } from "../utils/studioHelpers";
+import { Camera } from "../icons/SystemIcons";
import { useStudioShellContext } from "../contexts/StudioContext";
import { usePanelLayoutContext } from "../contexts/PanelLayoutContext";
import { trackStudioEvent } from "../utils/studioTelemetry";
-import { Button, buttonBase, buttonSizes, buttonVariants, cn, IconButton, Tooltip } from "./ui";
+import { Button, buttonBase, buttonSizes, buttonVariants, cn, Tooltip } from "./ui";
export interface StudioHeaderProps {
captureFrameHref: string;
@@ -138,16 +137,6 @@ function HyperframesLogo() {
);
}
-/** The Undo / Redo tooltip: the shortcut always, the last action's name when there is one. */
-export function historyTooltipLabel(
- action: "undo" | "redo",
- lastAction: string | null | undefined,
-): string {
- const shortcut = getHistoryShortcutLabel(action);
- const verb = action === "undo" ? "Undo" : "Redo";
- return lastAction ? `${verb} ${lastAction} (${shortcut})` : `${verb} (${shortcut})`;
-}
-
/**
* Does the header's Inspector button open the panel, or close it?
*
@@ -174,7 +163,7 @@ export function StudioHeader({
inspectorPanelActive,
onExport,
}: StudioHeaderProps) {
- const { projectId, editHistory, handleUndo, handleRedo, renderQueue } = useStudioShellContext();
+ const { projectId, renderQueue } = useStudioShellContext();
// effectiveRightCollapsed, not the raw intent: in the auto-railed state the
// intent is still "open" while the panel is hidden, so branching on intent
// made this button write rightCollapsed=true — and that value is synced into
@@ -194,125 +183,104 @@ export function StudioHeader({
<span className="text-step-11 font-medium text-text-1">{projectId}</span>
</div>
{/* Right: toolbar buttons */}
- <div className="flex items-center gap-1.5">
- <Tooltip label={historyTooltipLabel("undo", editHistory.undoLabel)} side="bottom">
- <IconButton
- aria-label="Undo"
- icon={<RotateCcw size={14} />}
- disabled={!editHistory.canUndo}
- onClick={() => {
- trackStudioEvent("toolbar_action", { action: "undo" });
- void handleUndo();
- }}
- />
- </Tooltip>
- <Tooltip label={historyTooltipLabel("redo", editHistory.redoLabel)} side="bottom">
- <IconButton
- aria-label="Redo"
- icon={<RotateCw size={14} />}
- disabled={!editHistory.canRedo}
- onClick={() => {
- trackStudioEvent("toolbar_action", { action: "redo" });
- void handleRedo();
- }}
- />
- </Tooltip>
- <Tooltip label={capturing ? "Capturing frame…" : "Capture current frame"} side="bottom">
- {/* A real download link, so it wears Button's recipe rather than being
+ <div className="flex items-center gap-3">
+ <div className="flex h-ctl items-center divide-x divide-border-strong overflow-hidden rounded-md border border-border-strong bg-bg-2">
+ <Tooltip label={capturing ? "Capturing frame…" : "Capture current frame"} side="bottom">
+ {/* A real download link, so it wears Button's recipe rather than being
one: `download` on an <a> is what saves the frame, and no <button>
can do that. `enabled:` never matches a link, so the ghost
variant's hover look is repeated unprefixed here. */}
- <a
- href={captureFrameHref}
- download={captureFrameFilename}
- onClick={(e) => {
- if (capturing) {
- e.preventDefault();
- return;
- }
- trackStudioEvent("toolbar_action", { action: "capture_frame" });
- handleCaptureFrameClick(e);
- }}
- onFocus={refreshCaptureFrameTime}
- onPointerDown={refreshCaptureFrameTime}
- aria-disabled={capturing || undefined}
- className={cn(
- buttonBase,
- buttonVariants.ghost,
- buttonSizes.md,
- capturing
- ? "text-text-4 cursor-default"
- : "hover:bg-hover hover:text-text-0 active:scale-[0.98]",
- )}
- aria-label={capturing ? "Capturing frame" : "Capture current frame"}
- >
- {capturing ? (
- <svg
- className="animate-spin motion-reduce:animate-none h-3.5 w-3.5"
- viewBox="0 0 24 24"
- fill="none"
- aria-hidden="true"
- >
- <circle
- className="opacity-25"
- cx="12"
- cy="12"
- r="10"
+ <a
+ href={captureFrameHref}
+ download={captureFrameFilename}
+ onClick={(e) => {
+ if (capturing) {
+ e.preventDefault();
+ return;
+ }
+ trackStudioEvent("toolbar_action", { action: "capture_frame" });
+ handleCaptureFrameClick(e);
+ }}
+ onFocus={refreshCaptureFrameTime}
+ onPointerDown={refreshCaptureFrameTime}
+ aria-disabled={capturing || undefined}
+ className={cn(
+ buttonBase,
+ buttonVariants.ghost,
+ buttonSizes.md,
+ "h-full rounded-none max-[1000px]:px-2",
+ capturing
+ ? "text-text-4 cursor-default"
+ : "hover:bg-hover hover:text-text-0 active:scale-[0.98]",
+ )}
+ aria-label={capturing ? "Capturing frame" : "Capture current frame"}
+ >
+ {capturing ? (
+ <svg
+ className="animate-spin motion-reduce:animate-none h-3.5 w-3.5"
+ viewBox="0 0 24 24"
+ fill="none"
+ aria-hidden="true"
+ >
+ <circle
+ className="opacity-25"
+ cx="12"
+ cy="12"
+ r="10"
+ stroke="currentColor"
+ strokeWidth="4"
+ />
+ <path
+ className="opacity-75"
+ fill="currentColor"
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
+ />
+ </svg>
+ ) : (
+ <Camera size={14} />
+ )}
+ <span className="max-[1000px]:hidden">{capturing ? "Capturing…" : "Capture"}</span>
+ </a>
+ </Tooltip>
+ <Tooltip label="Inspector" side="bottom">
+ <Button
+ variant="ghost"
+ aria-label="Inspector"
+ aria-pressed={inspectorButtonActive}
+ className={cn(
+ "h-full rounded-none",
+ inspectorButtonActive && "bg-hover text-accent enabled:hover:text-accent",
+ )}
+ icon={
+ <svg
+ width="12"
+ height="12"
+ viewBox="0 0 24 24"
+ fill="none"
stroke="currentColor"
- strokeWidth="4"
- />
- <path
- className="opacity-75"
- fill="currentColor"
- d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
- />
- </svg>
- ) : (
- <Camera size={14} />
- )}
- <span>{capturing ? "Capturing…" : "Capture"}</span>
- </a>
- </Tooltip>
- <Tooltip label="Inspector" side="bottom">
- <Button
- variant="ghost"
- aria-label="Inspector"
- aria-pressed={inspectorButtonActive}
- className={cn(
- "border",
- inspectorButtonActive
- ? "border-accent/30 bg-accent/10 text-accent"
- : "border-transparent",
- )}
- icon={
- <svg
- width="12"
- height="12"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- strokeWidth="2"
- >
- <circle cx="12" cy="12" r="10" />
- <polygon points="10 8 16 12 10 16" fill="currentColor" stroke="none" />
- </svg>
- }
- onClick={() => {
- if (shouldOpenInspector(effectiveRightCollapsed, inspectorPanelActive)) {
- trackStudioEvent("panel_toggle", { panel: "inspector", collapsed: false });
- setRightPanelTab("design");
- setRightCollapsed(false);
- return;
+ strokeWidth="2"
+ >
+ <circle cx="12" cy="12" r="10" />
+ <polygon points="10 8 16 12 10 16" fill="currentColor" stroke="none" />
+ </svg>
}
- trackStudioEvent("panel_toggle", { panel: "inspector", collapsed: true });
- // Keep the current selection when collapsing the Inspector — closing
- // the panel shouldn't deselect the element.
- setRightCollapsed(true);
- }}
- >
- Inspector
- </Button>
- </Tooltip>
+ onClick={() => {
+ if (shouldOpenInspector(effectiveRightCollapsed, inspectorPanelActive)) {
+ trackStudioEvent("panel_toggle", { panel: "inspector", collapsed: false });
+ setRightPanelTab("design");
+ setRightCollapsed(false);
+ return;
+ }
+ trackStudioEvent("panel_toggle", { panel: "inspector", collapsed: true });
+ // Keep the current selection when collapsing the Inspector — closing
+ // the panel shouldn't deselect the element.
+ setRightCollapsed(true);
+ }}
+ >
+ Inspector
+ </Button>
+ </Tooltip>
+ </div>
<Tooltip
label={
ffmpegMissing
diff --git a/packages/studio/src/components/TimelineHistoryButtons.dom.test.tsx b/packages/studio/src/components/TimelineHistoryButtons.dom.test.tsx
new file mode 100644
index 0000000000..230093002b
--- /dev/null
+++ b/packages/studio/src/components/TimelineHistoryButtons.dom.test.tsx
@@ -0,0 +1,117 @@
+// @vitest-environment happy-dom
+
+import { act } from "react";
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+import { cleanupMounted, mountHost } from "./ui/mountHost.testHelpers";
+import { isTypingTarget } from "../utils/typingTarget";
+import { shouldIgnorePlaybackShortcutTarget } from "../player/lib/playbackShortcuts";
+
+const editHistory = {
+ canUndo: false,
+ canRedo: false,
+ undoLabel: undefined as string | undefined,
+ redoLabel: undefined as string | undefined,
+};
+const handleUndo = vi.fn();
+const handleRedo = vi.fn();
+const trackStudioEvent = vi.fn();
+
+vi.mock("../contexts/StudioContext", () => ({
+ useStudioShellContext: () => ({ editHistory, handleUndo, handleRedo }),
+}));
+vi.mock("../utils/studioTelemetry", () => ({ trackStudioEvent }));
+
+const { TimelineHistoryButtons } = await import("./TimelineHistoryButtons");
+const { TimelineToolbar } = await import("./TimelineToolbar");
+
+beforeEach(() => {
+ Object.assign(editHistory, {
+ canUndo: false,
+ canRedo: false,
+ undoLabel: undefined,
+ redoLabel: undefined,
+ });
+ vi.clearAllMocks();
+});
+
+afterEach(cleanupMounted);
+
+const mount = mountHost;
+
+function button(host: HTMLElement, label: string): HTMLButtonElement {
+ const el = host.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`);
+ if (!el) throw new Error(`not rendered: ${label}`);
+ return el;
+}
+
+function click(el: HTMLElement): void {
+ act(() => {
+ el.dispatchEvent(new MouseEvent("click", { bubbles: true }));
+ });
+}
+
+it("calls handleUndo once and tracks the event when Undo is enabled", () => {
+ editHistory.canUndo = true;
+ const host = mount(<TimelineHistoryButtons />);
+
+ click(button(host, "Undo"));
+
+ expect(handleUndo).toHaveBeenCalledTimes(1);
+ expect(handleRedo).not.toHaveBeenCalled();
+ expect(trackStudioEvent).toHaveBeenCalledWith("toolbar_action", { action: "undo" });
+});
+
+it("calls handleRedo once and tracks the event when Redo is enabled", () => {
+ editHistory.canRedo = true;
+ const host = mount(<TimelineHistoryButtons />);
+
+ click(button(host, "Redo"));
+
+ expect(handleRedo).toHaveBeenCalledTimes(1);
+ expect(trackStudioEvent).toHaveBeenCalledWith("toolbar_action", { action: "redo" });
+});
+
+it("disables both buttons and ignores clicks on an empty history", () => {
+ const host = mount(<TimelineHistoryButtons />);
+
+ for (const label of ["Undo", "Redo"]) {
+ const el = button(host, label);
+ expect(el.disabled).toBe(true);
+ expect(el.className).toContain("cursor-not-allowed");
+ click(el);
+ }
+ expect(handleUndo).not.toHaveBeenCalled();
+ expect(handleRedo).not.toHaveBeenCalled();
+ expect(trackStudioEvent).not.toHaveBeenCalled();
+});
+
+it("leaves enabled buttons without the disabled attribute", () => {
+ editHistory.canUndo = true;
+ const el = button(mount(<TimelineHistoryButtons />), "Undo");
+
+ expect(el.disabled).toBe(false);
+ expect(el.className).not.toContain("cursor-not-allowed");
+});
+
+it("orders the toolbar Undo, Redo, Select, Razor", () => {
+ const host = mount(<TimelineToolbar />);
+ const labels = Array.from(host.querySelectorAll("button"))
+ .map((b) => b.getAttribute("aria-label"))
+ .filter((l) => l !== null)
+ .slice(0, 4);
+
+ expect(labels).toEqual(["Undo", "Redo", "Selection tool", "Razor tool"]);
+});
+
+it("classifies Undo and Redo for the hotkey filters at their new location (KTD13)", () => {
+ // The header's own version of this check dropped Undo/Redo when they moved
+ // here; a <button> is never a typing target and is always claimed by the
+ // playback filter, same as every other toolbar tool.
+ const host = mount(<TimelineHistoryButtons />);
+
+ for (const label of ["Undo", "Redo"]) {
+ const el = button(host, label);
+ expect(isTypingTarget(el), label).toBe(false);
+ expect(shouldIgnorePlaybackShortcutTarget(el), label).toBe(true);
+ }
+});
diff --git a/packages/studio/src/components/TimelineHistoryButtons.tsx b/packages/studio/src/components/TimelineHistoryButtons.tsx
new file mode 100644
index 0000000000..e779e8c75a
--- /dev/null
+++ b/packages/studio/src/components/TimelineHistoryButtons.tsx
@@ -0,0 +1,54 @@
+import { useStudioShellContext } from "../contexts/StudioContext";
+import { RotateCcw, RotateCw } from "../icons/SystemIcons";
+import { trackStudioEvent } from "../utils/studioTelemetry";
+import { historyTooltipLabel } from "../utils/studioHelpers";
+import { flatDisabled, flatIdle } from "./timelineToolbarStyles";
+import { Tooltip } from "./ui";
+
+interface HistoryButtonProps {
+ action: "undo" | "redo";
+ enabled: boolean;
+ label: string | undefined;
+ onClick: () => Promise<void> | void;
+}
+
+function HistoryButton({ action, enabled, label, onClick }: HistoryButtonProps) {
+ const Icon = action === "undo" ? RotateCcw : RotateCw;
+ return (
+ <Tooltip label={historyTooltipLabel(action, label)}>
+ <button
+ type="button"
+ aria-label={action === "undo" ? "Undo" : "Redo"}
+ disabled={!enabled}
+ className={enabled ? flatIdle : flatDisabled}
+ onClick={() => {
+ trackStudioEvent("toolbar_action", { action });
+ void onClick();
+ }}
+ >
+ <Icon size={16} />
+ </button>
+ </Tooltip>
+ );
+}
+
+/** Undo and Redo, on the one edit-history path the shell already owns. */
+export function TimelineHistoryButtons() {
+ const { editHistory, handleUndo, handleRedo } = useStudioShellContext();
+ return (
+ <>
+ <HistoryButton
+ action="undo"
+ enabled={editHistory.canUndo}
+ label={editHistory.undoLabel}
+ onClick={handleUndo}
+ />
+ <HistoryButton
+ action="redo"
+ enabled={editHistory.canRedo}
+ label={editHistory.redoLabel}
+ onClick={handleRedo}
+ />
+ </>
+ );
+}
diff --git a/packages/studio/src/components/TimelineToolbar.test.tsx b/packages/studio/src/components/TimelineToolbar.test.tsx
index ab07e8cd7a..416307e9ab 100644
--- a/packages/studio/src/components/TimelineToolbar.test.tsx
+++ b/packages/studio/src/components/TimelineToolbar.test.tsx
@@ -8,6 +8,14 @@ import { usePlayerStore } from "../player/store/playerStore";
import { makeSelection } from "../hooks/domSelectionTestHarness";
import { TimelineToolbar } from "./TimelineToolbar";
+vi.mock("../contexts/StudioContext", () => ({
+ useStudioShellContext: () => ({
+ editHistory: { canUndo: false, canRedo: false },
+ handleUndo: vi.fn(),
+ handleRedo: vi.fn(),
+ }),
+}));
+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
afterEach(() => {
diff --git a/packages/studio/src/components/TimelineToolbar.tsx b/packages/studio/src/components/TimelineToolbar.tsx
index c9a708b6c0..d31ff11c9c 100644
--- a/packages/studio/src/components/TimelineToolbar.tsx
+++ b/packages/studio/src/components/TimelineToolbar.tsx
@@ -22,6 +22,8 @@ import {
import { useTimelineZoom } from "../player/components/useTimelineZoom";
import { usePlayerStore, type TimelineElement } from "../player";
import { Tooltip } from "./ui";
+import { flatActive, flatBtn, flatDisabled, flatIdle } from "./timelineToolbarStyles";
+import { TimelineHistoryButtons } from "./TimelineHistoryButtons";
import { Scissors } from "../icons/SystemIcons";
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
import type { DomEditSelection } from "./editor/domEditingTypes";
@@ -186,19 +188,13 @@ export function TimelineToolbar({ domEditSession, onSplitElement }: TimelineTool
return () => window.removeEventListener("keydown", onKeyDown);
}, []);
- // CapCut-flat icon buttons: no per-button border/box chrome — a transparent
- // 28px hit area with a subtle rounded hover wash, consistent 16px glyphs.
- const flatBtn = "flex h-7 w-7 items-center justify-center rounded-md transition-colors";
- const flatIdle = `${flatBtn} text-neutral-400 hover:bg-white/6 hover:text-neutral-200 active:scale-[0.98]`;
- const flatActive = `${flatBtn} bg-white/8 text-neutral-100 active:scale-[0.98]`;
- const flatDisabled = `${flatBtn} text-neutral-700 cursor-not-allowed`;
-
return (
// The "TIMELINE" label is dropped for CapCut-like density — the pane's
// position (tracks right below) makes it self-evident.
<div className="border-b border-neutral-800/60">
<div className="flex items-center justify-between px-2 py-0.5">
<div className="flex items-center gap-0.5">
+ <TimelineHistoryButtons />
<Tooltip label="Selection tool (V)">
<button
type="button"
diff --git a/packages/studio/src/components/pointerTargetSize.test.tsx b/packages/studio/src/components/pointerTargetSize.test.tsx
index fd1923533a..4e34dd332f 100644
--- a/packages/studio/src/components/pointerTargetSize.test.tsx
+++ b/packages/studio/src/components/pointerTargetSize.test.tsx
@@ -6,6 +6,14 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { CompositionsTab } from "./sidebar/CompositionsTab";
import { TimelineToolbar } from "./TimelineToolbar";
+vi.mock("../contexts/StudioContext", () => ({
+ useStudioShellContext: () => ({
+ editHistory: { canUndo: false, canRedo: false },
+ handleUndo: vi.fn(),
+ handleRedo: vi.fn(),
+ }),
+}));
+
// WCAG 2.2 (2.5.8) requires a 24x24 CSS pixel pointer target. happy-dom has no
// CSS engine, so getBoundingClientRect() is 0x0 for everything here and the size
// itself cannot be measured — these assert the utility classes that PRODUCE the
diff --git a/packages/studio/src/components/timelineToolbarStyles.ts b/packages/studio/src/components/timelineToolbarStyles.ts
new file mode 100644
index 0000000000..fc6ed3259a
--- /dev/null
+++ b/packages/studio/src/components/timelineToolbarStyles.ts
@@ -0,0 +1,5 @@
+// CapCut-flat icon buttons: a transparent 28px hit area with a subtle hover wash.
+export const flatBtn = "flex h-7 w-7 items-center justify-center rounded-md transition-colors";
+export const flatIdle = `${flatBtn} text-neutral-400 hover:bg-white/6 hover:text-neutral-200 active:scale-[0.98]`;
+export const flatActive = `${flatBtn} bg-white/8 text-neutral-100 active:scale-[0.98]`;
+export const flatDisabled = `${flatBtn} text-neutral-700 cursor-not-allowed`;
diff --git a/packages/studio/src/utils/studioHelpers.test.ts b/packages/studio/src/utils/studioHelpers.test.ts
index 077c0c6b37..31b7bfb925 100644
--- a/packages/studio/src/utils/studioHelpers.test.ts
+++ b/packages/studio/src/utils/studioHelpers.test.ts
@@ -2,6 +2,7 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import {
+ historyTooltipLabel,
findMatchingTimelineElementId,
findTimelineIdByAncestor,
resolveDroppedAssetDimensions,
@@ -217,3 +218,20 @@ describe("resolveElementTrack", () => {
expect(resolveElementTrack({ authoredTrack: undefined, track: 3.6 })).toBe(4);
});
});
+
+describe("historyTooltipLabel", () => {
+ // A disabled control gets no pointer events, so its tooltip cannot be opened
+ // to read. The wording is checked here instead of through the DOM.
+ it("names the action that would be undone", () => {
+ expect(historyTooltipLabel("undo", "Move layer")).toMatch(/^Undo Move layer \(.+\)$/);
+ });
+
+ it("names the action that would be redone", () => {
+ expect(historyTooltipLabel("redo", "Move layer")).toMatch(/^Redo Move layer \(.+\)$/);
+ });
+
+ it("keeps the shortcut when the history is empty", () => {
+ expect(historyTooltipLabel("undo", undefined)).toMatch(/^Undo \(.+\)$/);
+ expect(historyTooltipLabel("redo", null)).toMatch(/^Redo \(.+\)$/);
+ });
+});
diff --git a/packages/studio/src/utils/studioHelpers.ts b/packages/studio/src/utils/studioHelpers.ts
index a5e4496fb8..28b027fa4b 100644
--- a/packages/studio/src/utils/studioHelpers.ts
+++ b/packages/studio/src/utils/studioHelpers.ts
@@ -119,13 +119,23 @@ export function shouldIgnoreHistoryShortcut(target: EventTarget | null): boolean
return isTypingTarget(target);
}
-export function getHistoryShortcutLabel(action: "undo" | "redo"): string {
+function getHistoryShortcutLabel(action: "undo" | "redo"): string {
const isMac =
typeof navigator !== "undefined" && /Mac|iPhone|iPad|iPod/i.test(navigator.platform);
const modifier = isMac ? "Cmd" : "Ctrl";
return action === "undo" ? `${modifier}+Z` : `${modifier}+Shift+Z`;
}
+/** The Undo / Redo tooltip: the shortcut always, the last action's name when there is one. */
+export function historyTooltipLabel(
+ action: "undo" | "redo",
+ lastAction: string | null | undefined,
+): string {
+ const shortcut = getHistoryShortcutLabel(action);
+ const verb = action === "undo" ? "Undo" : "Redo";
+ return lastAction ? `${verb} ${lastAction} (${shortcut})` : `${verb} (${shortcut})`;
+}
+
export type ElementMatchSelection = Pick<
DomEditSelection,
| "id"