Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
feat(studio): trimming a clip shows the snap guide and the frame at the dragged edge (#4163)
Miguel Ángel86667203ce14
diff --git a/packages/studio/src/player/components/Timeline.tsx b/packages/studio/src/player/components/Timeline.tsxindex ec5f0676b9..2af548aca4 100644--- a/packages/studio/src/player/components/Timeline.tsx+++ b/packages/studio/src/player/components/Timeline.tsx@@ -233,6 +233,7 @@ export const Timeline = memo(function Timeline({onResizeElement: pinnedOnResizeElement,onResizeElements: pinnedOnResizeElements,onBlockedEditAttempt,+ onSeek,setShowPopover,setRangeSelectionRef,readZIndex: zSyncEnabled ? readClipZIndex : undefined,diff --git a/packages/studio/src/player/components/TimelineCanvas.tsx b/packages/studio/src/player/components/TimelineCanvas.tsxindex 5c81a60f59..1debf1c4f7 100644--- a/packages/studio/src/player/components/TimelineCanvas.tsx+++ b/packages/studio/src/player/components/TimelineCanvas.tsx@@ -24,6 +24,7 @@ import type { TimelineLaneBaseProps } from "./timelineLaneProps";import type { TimelineLaneGapStrips } from "./useTimelineGapHighlights";import { getTimelineElementIdentity } from "../lib/timelineElementHelpers";import { TimelineGestureOverlay } from "./TimelineGestureOverlay";+import { resolveSnapGuide } from "./timelineSnapping";interface TimelineCanvasProps extends TimelineLaneBaseProps {major: number[];@@ -48,7 +49,8 @@ interface TimelineCanvasProps extends TimelineLaneBaseProps {const DROP_PREVIEW_SECONDS = 3;export const TimelineCanvas = memo(function TimelineCanvas(props: TimelineCanvasProps) {- const { draggedClip, scrollRef, selectedElementIds, displayTrackOrder } = props;+ const { draggedClip, resizingClip, scrollRef, selectedElementIds, displayTrackOrder } = props;+ const snapGuide = resolveSnapGuide(draggedClip, resizingClip);const draggedRowIndex =draggedClip?.started === true ? displayTrackOrder.indexOf(draggedClip.previewTrack) : -1;const dropTrackIndex = props.dropPreview@@ -120,6 +122,7 @@ export const TimelineCanvas = memo(function TimelineCanvas(props: TimelineCanvas<TimelineLanes{...props}+ snapGuide={snapGuide}draggedElement={draggedElement}multiDragPreview={multiDragPreview}onToggleTrackHidden={onToggleTrackHidden}@@ -222,18 +225,18 @@ export const TimelineCanvas = memo(function TimelineCanvas(props: TimelineCanvas/>)}- {/* Snap guide for non-beat targets during clip drag */}- {draggedClip?.started && draggedClip.snapTime != null && draggedClip.snapType !== "beat" && (+ {/* Snap guide for non-beat targets during a clip move or trim */}+ {snapGuide && snapGuide.type !== "beat" && (<divclassName="absolute pointer-events-none"style={{- left: props.contentOrigin + draggedClip.snapTime * props.pps,+ left: props.contentOrigin + snapGuide.time * props.pps,top: RULER_H,bottom: 0,width: 1,- background: draggedClip.snapType === "playhead" ? "#3CE6AC" : "rgba(255,255,255,0.6)",+ background: snapGuide.type === "playhead" ? "#3CE6AC" : "rgba(255,255,255,0.6)",boxShadow:- draggedClip.snapType === "playhead"+ snapGuide.type === "playhead"? "0 0 6px rgba(60,230,172,0.5)": "0 0 6px rgba(255,255,255,0.4)",zIndex: 60,diff --git a/packages/studio/src/player/components/TimelineLanes.test.tsx b/packages/studio/src/player/components/TimelineLanes.test.tsxindex e9f2e4e601..2cf6d51b3d 100644--- a/packages/studio/src/player/components/TimelineLanes.test.tsx+++ b/packages/studio/src/player/components/TimelineLanes.test.tsx@@ -72,6 +72,7 @@ interface RenderLanesOptions {onContextMenuLane?: (e: React.MouseEvent, track: number, time: number) => void;hoveredClip?: string | null;renderClipContent?: React.ComponentProps<typeof TimelineLanes>["renderClipContent"];+ snapGuide?: { time: number; type: "beat" | "clip-edge" | "playhead" } | null;}function renderLanes(options: RenderLanesOptions = {}): {@@ -141,6 +142,7 @@ function renderLanes(options: RenderLanesOptions = {}): {renderClipContent={next.renderClipContent}draggedClip={next.draggedClip ?? null}draggedElement={null}+ snapGuide={next.snapGuide ?? null}multiDragPreview={next.multiDragPreview ?? null}blockedClipRef={createRef<BlockedClipState | null>()}suppressClickRef={{ current: false }}@@ -179,6 +181,36 @@ function visibilityLabels(host: HTMLElement): (string | null)[] {);}+/** The beat guide's own highlight div, keyed by the green glow every other beat lacks. */+function beatHighlight(host: HTMLElement): HTMLElement | undefined {+ return Array.from(host.querySelectorAll("div")).find((div) =>+ (div.style.boxShadow ?? "").includes("34,197,94"),+ );+}++describe("TimelineLanes beat guide", () => {+ it("draws the beat highlight from snapGuide, not from the stale draggedClip prop", () => {+ const view = renderLanes({+ elements: [element("clip-a", TRACK_A)],+ snapGuide: { time: 1.5, type: "beat" },+ });++ expect(beatHighlight(view.host)?.style.left).toBe("150px");+ act(() => view.root.unmount());+ });++ it("clears the highlight once the trim it belonged to ends", () => {+ const view = renderLanes({+ elements: [element("clip-a", TRACK_A)],+ snapGuide: { time: 1.5, type: "beat" },+ });+ view.rerender({ elements: [element("clip-a", TRACK_A)], snapGuide: null });++ expect(beatHighlight(view.host)).toBeUndefined();+ act(() => view.root.unmount());+ });+});+describe("TimelineLanes track numbering", () => {// Screen readers literally announced "Hide track 0.16666666666666666".it("numbers tracks contiguously from 1 regardless of the fractional sort keys", () => {diff --git a/packages/studio/src/player/components/TimelineLanes.tsx b/packages/studio/src/player/components/TimelineLanes.tsxindex 2243a79673..3921bece03 100644--- a/packages/studio/src/player/components/TimelineLanes.tsx+++ b/packages/studio/src/player/components/TimelineLanes.tsx@@ -59,6 +59,7 @@ export function TimelineLanes({hoveredClip,draggedClip,draggedElement,+ snapGuide,multiDragPreview,blockedClipRef,suppressClickRef,@@ -331,11 +332,7 @@ export function TimelineLanes({beatTimes={beatAnalysis?.beatTimes}beatStrengths={beatAnalysis?.beatStrengths}pps={pps}- highlightTime={- draggedClip?.started && draggedClip.snapType === "beat"- ? draggedClip.snapTime- : null- }+ highlightTime={snapGuide?.type === "beat" ? snapGuide.time : null}renderTimeRange={rowsVirtualized ? renderTimeRange : undefined}/>{/* Beat dots on the active track (the one holding the selection),diff --git a/packages/studio/src/player/components/TimelineTypes.ts b/packages/studio/src/player/components/TimelineTypes.tsindex eb2e6ebb4c..da7a727046 100644--- a/packages/studio/src/player/components/TimelineTypes.ts+++ b/packages/studio/src/player/components/TimelineTypes.ts@@ -12,7 +12,8 @@ export interface TimelineClipRenderContext {export interface TimelineProps extends TimelineDropCallbacks, TimelineEditOverrides {/** Project-scoped reset boundary; soft source refreshes retain the same epoch. */sessionEpoch?: number;- onSeek?: (time: number) => void;+ /** keepPlaying: true preserves the current play state across the seek. */+ onSeek?: (time: number, options?: { keepPlaying?: boolean }) => void;onDrillDown?: (element: TimelineElement) => void;renderClipContent?: (element: TimelineElement,diff --git a/packages/studio/src/player/components/timelineClipDragPreview.ts b/packages/studio/src/player/components/timelineClipDragPreview.tsindex a0b2b342dd..a53f7e8764 100644--- a/packages/studio/src/player/components/timelineClipDragPreview.ts+++ b/packages/studio/src/player/components/timelineClipDragPreview.ts@@ -12,6 +12,7 @@ import {snapMoveToTargets,snapTimelineTime,type TimelineSnapTarget,+ type TimelineSnapType,} from "./timelineSnapping";import { resolveInsertRow, resolveZoneDropPlacement } from "./timelineCollision";import {@@ -21,11 +22,13 @@ import {import { clampGroupMoveDelta } from "./timelineMultiDragPreview";import type { DraggedClipState, ResizingClipState } from "./timelineClipDragTypes";import { resolveDragLandingStart } from "./timelineDragLanding";+import { STUDIO_PREVIEW_FPS } from "../lib/time";/** Snap-target builder closure supplied by the hook (closes over refs + store). */type BuildSnapTargets = (excludeElementKey: string | null,includeBeats: boolean,+ includePlayhead?: boolean,) => TimelineSnapTarget[];export interface DragPreviewContext {@@ -223,6 +226,14 @@ export function computeDragPreview(};}+/** One frame: the last visible frame of a clip sits just before its end time. */+const TRIM_END_FRAME_LEAD_S = 1 / STUDIO_PREVIEW_FPS;++/** The composition time whose frame a trim shows: the edge being dragged. */+export function trimPreviewTime(edge: "start" | "end", start: number, duration: number): number {+ return edge === "start" ? start : Math.max(start, start + duration - TRIM_END_FRAME_LEAD_S);+}+export interface ResizePreviewContext {scroll: HTMLDivElement | null;pps: number;@@ -234,6 +245,9 @@ export interface ResizePreviewResult {previewStart: number;previewDuration: number;previewPlaybackStart?: number;+ /** The target the trimmed edge snapped to; null when the edge is free. */+ snapTime: number | null;+ snapType: TimelineSnapType | null;}/** Compute the trim preview for a pointer x (pure — the hook applies the state). */@@ -287,28 +301,31 @@ export function computeResizePreview(effectiveClientX,);- // Snap edge to unified targets (beats + clip edges + playhead) when available.- // The snap must stay inside the same limits resolveTimelineResize enforces, or- // it would push the edge past the available source media / composition end.- // The music track defines the beats, so it must not snap to them — but it- // still snaps to the playhead and other clip edges.+ // Snap to beats and clip edges, never the playhead (the dragged edge drives+ // its own preview seek, so that would be circular). Stay inside the same+ // limits resolveTimelineResize enforces. The music track defines the+ // beats, so it must not snap to them, but still snaps to clip edges.const trimTargets = buildSnapTargets(resize.element.key ?? resize.element.id,!isMusicTrack(resize.element),+ false,);+ let snap: TimelineSnapTarget | null = null;if (trimTargets.length > 0) {const snapSecs = TIMELINE_SNAP_PX / Math.max(pps, 1);if (resize.edge === "end") {const edgeTime = nextResize.start + nextResize.duration;- const snapped = snapTimelineTime(edgeTime, trimTargets, snapSecs).time;+ const { time: snapped, target } = snapTimelineTime(edgeTime, trimTargets, snapSecs);// Stay within [start+minDuration, maxEnd] so the snap can't create a// degenerate clip or run past the source/composition limit.const snappedDuration = Math.round((snapped - nextResize.start) * 1000) / 1000;- if (snapped !== edgeTime && snapped <= maxEnd + 1e-6 && snappedDuration >= 0.05) {- nextResize = { ...nextResize, duration: snappedDuration };+ if (target && snapped <= maxEnd + 1e-6 && snappedDuration >= 0.05) {+ // An edge already on the target still owns the guide; only move it when off.+ if (snapped !== edgeTime) nextResize = { ...nextResize, duration: snappedDuration };+ snap = target;}} else {- const snapped = snapTimelineTime(nextResize.start, trimTargets, snapSecs).time;+ const { time: snapped, target } = snapTimelineTime(nextResize.start, trimTargets, snapSecs);const delta = nextResize.start - snapped; // >0 when snapping left// Leftward snap reveals more source; cap so playbackStart can't go < 0.const maxLeftDelta =@@ -318,22 +335,20 @@ export function computeResizePreview(// Also require the resulting duration to stay >= minDuration so a rightward// snap (delta < 0) can't collapse the clip to zero/negative.const snappedDuration = Math.round((nextResize.duration + delta) * 1000) / 1000;- if (- snapped !== nextResize.start &&- snapped >= 0 &&- delta <= maxLeftDelta + 1e-6 &&- snappedDuration >= 0.05- ) {- nextResize = {- ...nextResize,- start: snapped,- duration: snappedDuration,- playbackStart:- nextResize.playbackStart != null- ? Math.round(Math.max(0, nextResize.playbackStart - delta * playbackRate) * 1000) /- 1000- : undefined,- };+ if (target && snapped >= 0 && delta <= maxLeftDelta + 1e-6 && snappedDuration >= 0.05) {+ if (snapped !== nextResize.start) {+ nextResize = {+ ...nextResize,+ start: snapped,+ duration: snappedDuration,+ playbackStart:+ nextResize.playbackStart != null+ ? Math.round(Math.max(0, nextResize.playbackStart - delta * playbackRate) * 1000) /+ 1000+ : undefined,+ };+ }+ snap = target;}}}@@ -343,6 +358,8 @@ export function computeResizePreview(previewStart: nextResize.start,previewDuration: nextResize.duration,previewPlaybackStart: nextResize.playbackStart,+ snapTime: snap?.time ?? null,+ snapType: snap?.type ?? null,};}@@ -359,11 +376,18 @@ export function previewGroupResize() => void,): void {const grabbedChange = applyTimelineGroupResizePreview(session, next);+ const previewStart = grabbedChange?.start ?? next.previewStart;+ const previewDuration = grabbedChange?.duration ?? next.previewDuration;+ // A member clamp can pull the grabbed edge off the raw snap target; then no guide.+ const edgeTime = session.edge === "end" ? previewStart + previewDuration : previewStart;+ const stillSnapped = next.snapTime != null && Math.abs(edgeTime - next.snapTime) < 1e-3;setResizeState({originScrollLeft: next.originScrollLeft,- previewStart: grabbedChange?.start ?? next.previewStart,- previewDuration: grabbedChange?.duration ?? next.previewDuration,+ previewStart,+ previewDuration,previewPlaybackStart: grabbedChange?.playbackStart ?? next.previewPlaybackStart,+ snapTime: stillSnapped ? next.snapTime : null,+ snapType: stillSnapped ? next.snapType : null,groupPreview: session.changes,});}diff --git a/packages/studio/src/player/components/timelineClipDragTypes.ts b/packages/studio/src/player/components/timelineClipDragTypes.tsindex 251a299f6d..87bc4b1227 100644--- a/packages/studio/src/player/components/timelineClipDragTypes.ts+++ b/packages/studio/src/player/components/timelineClipDragTypes.ts@@ -57,6 +57,9 @@ export interface ResizingClipState {previewStart: number;previewDuration: number;previewPlaybackStart?: number;+ /** Snap target the trimmed edge landed on, for the guide highlight. */+ snapTime?: number | null;+ snapType?: TimelineSnapType | null;/** Coordinator-owned group projection; canonical elements change only on commit. */groupPreview?: readonly {key: string;diff --git a/packages/studio/src/player/components/timelineLaneProps.ts b/packages/studio/src/player/components/timelineLaneProps.tsindex be09495287..5c997850bf 100644--- a/packages/studio/src/player/components/timelineLaneProps.ts+++ b/packages/studio/src/player/components/timelineLaneProps.ts@@ -8,6 +8,7 @@ import type { TrackVisualStyle } from "./timelineIcons";import type { DraggedClipState, ResizingClipState, BlockedClipState } from "./useTimelineClipDrag";import type { TimelineClipIndex, TimelineTimeRange } from "../lib/timelineClipIndex";import type { TimelineRowGeometry } from "./timelineLayout";+import type { TimelineSnapTarget } from "./timelineSnapping";import type { TimelineVirtualRow } from "./useTimelineVirtualRows";import type { MultiDragPreviewInput } from "./timelineMultiDragPreview";import type { TimelineEditCallbacks } from "./timelineCallbacks";@@ -112,6 +113,8 @@ export interface TimelineLaneBaseProps {export interface TimelineLanesProps extends TimelineLaneBaseProps {/** Live-derived by TimelineCanvas from {@link TimelineLaneBaseProps.draggedClip}. */draggedElement: TimelineElement | null;+ /** Live move or trim snap target, resolved once by TimelineCanvas. */+ snapGuide: TimelineSnapTarget | null;multiDragPreview: MultiDragPreviewInput | null;onToggleTrackHidden: TimelineEditCallbacks["onToggleTrackHidden"];onTogglePropertyGroupKeyframe: TimelineEditCallbacks["onTogglePropertyGroupKeyframe"];diff --git a/packages/studio/src/player/components/timelineSnapping.test.ts b/packages/studio/src/player/components/timelineSnapping.test.tsindex 35980b85e3..1d881ff1fb 100644--- a/packages/studio/src/player/components/timelineSnapping.test.ts+++ b/packages/studio/src/player/components/timelineSnapping.test.ts@@ -4,6 +4,7 @@ import {collectTimelineSnapTargets,snapMoveToTargets,snapTimelineTime,+ resolveSnapGuide,} from "./timelineSnapping";describe("collectTimelineSnapTargets", () => {@@ -26,6 +27,18 @@ describe("collectTimelineSnapTargets", () => {expect(targets).toContainEqual({ time: 0.5, type: "beat" });});+ it("omits the playhead when includePlayhead is false, for a trim", () => {+ const targets = collectTimelineSnapTargets({+ elements,+ playheadTime: 7.25,+ beatTimes: [0.5],+ includePlayhead: false,+ });+ expect(targets.some((t) => t.type === "playhead")).toBe(false);+ expect(targets).toContainEqual({ time: 2, type: "clip-edge" });+ expect(targets).toContainEqual({ time: 0.5, type: "beat" });+ });+it("excludes the dragged element's own edges", () => {const targets = collectTimelineSnapTargets({elements,@@ -132,3 +145,17 @@ describe("snapMoveToTargets", () => {expect(r.snapTime).toBeNull();});});++describe("resolveSnapGuide", () => {+ it("prefers a started move, falls back to a trim, and is null when neither snapped", () => {+ const move = { started: true, snapTime: 2, snapType: "playhead" as const };+ const trim = { snapTime: 5, snapType: "clip-edge" as const };+ expect(resolveSnapGuide(move, trim)).toEqual({ time: 2, type: "playhead" });+ expect(resolveSnapGuide({ ...move, started: false }, trim)).toEqual({+ time: 5,+ type: "clip-edge",+ });+ expect(resolveSnapGuide(null, { snapTime: null, snapType: null })).toBeNull();+ expect(resolveSnapGuide(null, null)).toBeNull();+ });+});diff --git a/packages/studio/src/player/components/timelineSnapping.ts b/packages/studio/src/player/components/timelineSnapping.tsindex 30d1175273..8f11ab67e1 100644--- a/packages/studio/src/player/components/timelineSnapping.ts+++ b/packages/studio/src/player/components/timelineSnapping.ts@@ -7,6 +7,16 @@ export interface TimelineSnapTarget {type: TimelineSnapType;}+/** The guide the canvas draws: the live move's snap target, else the live trim's. */+export function resolveSnapGuide(+ moving: { started: boolean; snapTime: number | null; snapType: TimelineSnapType | null } | null,+ trimming: { snapTime?: number | null; snapType?: TimelineSnapType | null } | null,+): TimelineSnapTarget | null {+ const source = moving?.started ? moving : trimming;+ if (source?.snapTime == null || source.snapType == null) return null;+ return { time: source.snapTime, type: source.snapType };+}+/** Pixel radius within which a time snaps to a target (matches historical beat snap). */export const TIMELINE_SNAP_PX = 8;@@ -21,6 +31,8 @@ export function collectTimelineSnapTargets(input: {playheadTime: number | null;beatTimes: readonly number[];excludeElementKey?: string | null;+ /** A trim excludes the playhead: the dragged edge drives it, so snapping to it is circular. */+ includePlayhead?: boolean;}): TimelineSnapTarget[] {const byTime = new Map<number, TimelineSnapTarget>();const add = (time: number, type: TimelineSnapType) => {@@ -38,7 +50,8 @@ export function collectTimelineSnapTargets(input: {add(el.start, "clip-edge");add(el.start + el.duration, "clip-edge");}- if (input.playheadTime != null) add(input.playheadTime, "playhead");+ if (input.playheadTime != null && input.includePlayhead !== false)+ add(input.playheadTime, "playhead");return Array.from(byTime.values()).sort((a, b) => a.time - b.time);}diff --git a/packages/studio/src/player/components/useTimelineClipDrag.resize.test.tsx b/packages/studio/src/player/components/useTimelineClipDrag.resize.test.tsxindex 7aae044a72..fd5cb0fadd 100644--- a/packages/studio/src/player/components/useTimelineClipDrag.resize.test.tsx+++ b/packages/studio/src/player/components/useTimelineClipDrag.resize.test.tsx@@ -31,10 +31,14 @@ afterEach(() => {function renderResizeHarness(elements: TimelineElement[],selected: string[],- options: { wireGroupResize?: boolean } = {},+ options: {+ wireGroupResize?: boolean;+ snap?: boolean;+ onSeek?: (time: number, seekOptions?: { keepPlaying?: boolean }) => void;+ } = {},) {usePlayerStore.getState().setElements(elements);- usePlayerStore.setState({ timelineSnapEnabled: false });+ usePlayerStore.setState({ timelineSnapEnabled: options.snap === true });usePlayerStore.getState().setSelectedElementIds(new Set(selected));const scroll = document.createElement("div");@@ -61,6 +65,7 @@ function renderResizeHarness(onMoveElement,onBlockedEditAttempt,onResizeElements: options.wireGroupResize === false ? undefined : onResizeElements,+ onSeek: options.onSeek,setShowPopover: vi.fn(),setRangeSelectionRef: { current: vi.fn() },sessionEpoch,@@ -92,6 +97,9 @@ function renderResizeHarness(getResizeProjection() {return resizingClip?.groupPreview ?? [];},+ getResizingClip() {+ return resizingClip;+ },getBlockedClip() {return blockedClipRef?.current ?? null;},@@ -441,3 +449,129 @@ describe("useTimelineClipDrag — multi-select group resize (restored)", () => {h.unmount();});});++describe("useTimelineClipDrag — trim guide and preview frame", () => {+ /** Playhead at 1.25s that follows preview seeks; clip a's end edge grabbed and dragged once. */+ function trimEndWithSeekingPlayhead(state: { isPlaying?: boolean } = {}) {+ usePlayerStore.setState({ currentTime: 1.25, ...state });+ const onSeek = vi.fn((t: number) => usePlayerStore.setState({ currentTime: t }));+ const a = el("a", { start: 1, duration: 2 });+ const h = renderResizeHarness([a], [], { onSeek });+ h.startResize(a, "end");+ h.movePointer(50);+ return { onSeek, h };+ }++ /** Clip a (0-2s) with neighbour b starting at 5s, snapping on, a's end edge grabbed. */+ function trimAEndBesideB() {+ const a = el("a", { start: 0, duration: 2 });+ const b = el("b", { start: 5, duration: 2 });+ const h = renderResizeHarness([a, b], [], { snap: true });+ h.startResize(a, "end");+ return h;+ }++ it("publishes the snap target while a trimmed edge is on a neighbour edge", () => {+ const h = trimAEndBesideB();+ h.movePointer(296); // a's end lands at 4.96s, 4px from b's start+ expect(h.getResizingClip()).toMatchObject({ snapTime: 5, snapType: "clip-edge" });+ h.unmount();+ });++ it("keeps the guide when the trimmed edge sits exactly on the neighbour edge", () => {+ const h = trimAEndBesideB();+ h.movePointer(300);+ expect(h.getResizingClip()).toMatchObject({ snapTime: 5, previewDuration: 5 });+ h.unmount();+ });++ it("publishes no snap target when the trimmed edge is free", () => {+ const h = trimAEndBesideB();+ h.movePointer(150);+ expect(h.getResizingClip()).toMatchObject({ snapTime: null, snapType: null });+ h.unmount();+ });++ it("never snaps a trimmed edge to the playhead — the edge drives its own seek", () => {+ usePlayerStore.setState({ currentTime: 5 }); // no clip edge or beat nearby, only the playhead+ const a = el("a", { start: 0, duration: 2 });+ const h = renderResizeHarness([a], [], { snap: true });+ h.startResize(a, "end");+ h.movePointer(296); // a's end lands at 4.96s, 4px from the playhead+ expect(h.getResizingClip()).toMatchObject({+ snapTime: null,+ snapType: null,+ previewDuration: 4.96,+ });+ h.unmount();+ });++ it("shows the frame at the dragged edge, then puts the playhead back on release", async () => {+ usePlayerStore.setState({ currentTime: 1.25 });+ const onSeek = vi.fn();+ const a = el("a", { start: 1, duration: 2 });+ const h = renderResizeHarness([a], [], { onSeek });+ h.startResize(a, "end");+ h.movePointer(50);+ expect(onSeek).toHaveBeenLastCalledWith(3.5 - 1 / 30, { keepPlaying: true });+ await h.dropPointer();+ expect(onSeek).toHaveBeenLastCalledWith(1.25, { keepPlaying: true });+ h.unmount();+ });++ it("previews the new in-point when the start edge is trimmed", () => {+ const onSeek = vi.fn();+ const a = el("a", { start: 1, duration: 2 });+ const h = renderResizeHarness([a], [], { onSeek });+ h.startResize(a, "start");+ h.movePointer(50);+ expect(onSeek).toHaveBeenLastCalledWith(1.5, { keepPlaying: true });+ h.unmount();+ });++ it("publishes the guide when the start edge snaps to a neighbour's end", () => {+ // playbackStart leaves source to reveal when the in-point moves left.+ const a = el("a", { start: 3, duration: 2, playbackStart: 5 });+ const b = el("b", { start: 0, duration: 2 });+ const h = renderResizeHarness([a, b], [], { snap: true });+ h.startResize(a, "start");+ h.movePointer(-96); // a's start lands at 2.04s, 4px from b's end+ expect(h.getResizingClip()).toMatchObject({ snapTime: 2, previewStart: 2 });+ h.unmount();+ });++ it("restores the playhead it had before the first preview seek, not a seeked time", async () => {+ const { onSeek, h } = trimEndWithSeekingPlayhead();+ h.movePointer(80);+ h.movePointer(120);+ await h.dropPointer();+ expect(onSeek).toHaveBeenLastCalledWith(1.25, { keepPlaying: true });+ h.unmount();+ });++ it("leaves the playhead where playback is when a trim is released while playing", async () => {+ const { onSeek, h } = trimEndWithSeekingPlayhead({ isPlaying: true });+ h.movePointer(120);+ const callsBeforeRelease = onSeek.mock.calls.length;+ await h.dropPointer();+ expect(onSeek).toHaveBeenCalledTimes(callsBeforeRelease);+ expect(onSeek).not.toHaveBeenCalledWith(1.25, expect.anything());+ usePlayerStore.setState({ isPlaying: false });+ h.unmount();+ });++ it("draws no guide and seeks to the rendered edge when a group member clamps the trim", () => {+ const onSeek = vi.fn();+ const a = el("a", { start: 0, duration: 4 });+ const b = el("b", { start: 0, duration: 1 });+ const c = el("c", { start: 2, duration: 1 });+ const h = renderResizeHarness([a, b, c], ["a", "b"], { snap: true, onSeek });+ h.startResize(a, "end");+ h.movePointer(-198); // a's raw end 2.02s snaps to c at 2s; b clamps the shared delta+ const clip = h.getResizingClip()!;+ expect(clip.previewStart + clip.previewDuration).toBeCloseTo(3.1, 3);+ expect(clip).toMatchObject({ snapTime: null, snapType: null });+ expect(onSeek).toHaveBeenLastCalledWith(expect.closeTo(3.1 - 1 / 30, 3), { keepPlaying: true });+ h.unmount();+ });+});diff --git a/packages/studio/src/player/components/useTimelineClipDrag.ts b/packages/studio/src/player/components/useTimelineClipDrag.tsindex ea44dda075..7c49eda117 100644--- a/packages/studio/src/player/components/useTimelineClipDrag.ts+++ b/packages/studio/src/player/components/useTimelineClipDrag.ts@@ -17,6 +17,7 @@ import type { TimelineEditCallbacks } from "./timelineCallbacks";import {computeDragPreview,computeResizePreview,+ trimPreviewTime,previewGroupResize,type ResizePreviewResult,} from "./timelineClipDragPreview";@@ -64,6 +65,8 @@ interface UseTimelineClipDragInput {) => Promise<void> | void;onResizeElements?: NonNullable<TimelineEditCallbacks["onResizeElements"]>;onBlockedEditAttempt?: (element: TimelineElement, intent: BlockedClipState["intent"]) => void;+ /** Seeks the preview; a trim shows the frame at its dragged edge. */+ onSeek?: (time: number, options?: { keepPlaying?: boolean }) => void;setShowPopover: (show: boolean) => void;/** Stable ref to the range selection setter — wired after mount to break circular dependency. */setRangeSelectionRef: React.RefObject<((sel: null) => void) | null>;@@ -92,6 +95,7 @@ export function useTimelineClipDrag({onResizeElement,onResizeElements,onBlockedEditAttempt,+ onSeek,setShowPopover,setRangeSelectionRef,readZIndex,@@ -149,11 +153,15 @@ export function useTimelineClipDrag({const dragAudioTracksRef = useRef<ReadonlySet<number> | null>(null);const buildSnapTargets = useCallback(- (excludeElementKey: string | null, includeBeats: boolean): TimelineSnapTarget[] => {+ (+ excludeElementKey: string | null,+ includeBeats: boolean,+ includePlayhead = true,+ ): TimelineSnapTarget[] => {// Magnet off ⇒ no targets and no scan; do NOT cache so a mid-gesture toggle// back on starts scanning immediately (preserves the existing skip).if (!snapContextRef.current.enabled) return [];- const cacheKey = `${excludeElementKey ?? ""}|${includeBeats ? 1 : 0}`;+ const cacheKey = `${excludeElementKey ?? ""}|${includeBeats ? 1 : 0}|${includePlayhead ? 1 : 0}`;const cached = snapTargetsCacheRef.current.get(cacheKey);if (cached) return cached;const targets = collectTimelineSnapTargets({@@ -161,6 +169,7 @@ export function useTimelineClipDrag({playheadTime: usePlayerStore.getState().currentTime,beatTimes: includeBeats ? snapContextRef.current.beatTimes : [],excludeElementKey,+ includePlayhead,});snapTargetsCacheRef.current.set(cacheKey, targets);return targets;@@ -244,6 +253,10 @@ export function useTimelineClipDrag({onResizeElementRef.current = onResizeElement;const onResizeElementsRef = useRef(onResizeElements);onResizeElementsRef.current = onResizeElements;+ const onSeekRef = useRef(onSeek);+ onSeekRef.current = onSeek;+ // Playhead time before the first trim preview seek; restored when the gesture ends.+ const trimSeekOriginRef = useRef<number | null>(null);const readZIndexRef = useRef(readZIndex);readZIndexRef.current = readZIndex;const onStackingPatchesRef = useRef(onStackingPatches);@@ -292,10 +305,17 @@ export function useTimelineClipDrag({pps: ppsRef.current,buildSnapTargets,});- const setResizeState = (v: ResizePreviewResult) =>+ trimSeekOriginRef.current ??= usePlayerStore.getState().currentTime;+ const setResizeState = (v: ResizePreviewResult) => {+ // A trim never changes the play state: keepPlaying lets seek() decide,+ // and it only resumes playback if it was already playing.+ onSeekRef.current?.(trimPreviewTime(resize.edge, v.previewStart, v.previewDuration), {+ keepPlaying: true,+ });publishResizingClip(resizingClipRef.current ? { ...resizingClipRef.current, started: true, ...v } : null,);+ };// Group resize: a capability-clean multi-selection resizes rigidly by one// shared, member-clamped delta (legacy main 36413da7f). The grabbed clip@@ -338,6 +358,13 @@ export function useTimelineClipDrag({cancelAnimationFrame(clipDragScrollRaf.current);clipDragScrollRaf.current = 0;}+ if (trimSeekOriginRef.current != null) {+ // Paused: put the playhead back. Playing: leave it, a backward jump would rewind live playback.+ if (!usePlayerStore.getState().isPlaying) {+ onSeekRef.current?.(trimSeekOriginRef.current, { keepPlaying: true });+ }+ trimSeekOriginRef.current = null;+ }// Gesture teardown: drop frozen caches so the next gesture reads fresh state.snapTargetsCacheRef.current.clear();dragAudioTracksRef.current = null;