Skip to content

Open source CapCut alternative.

TypeScript

feat(site): paste lands under the timeline skimmer

David Lece11530fd710
diff --git a/site/src/cut/lib/store.test.ts b/site/src/cut/lib/store.test.ts
index 130c26fc..0bd5b086 100644
--- a/site/src/cut/lib/store.test.ts
+++ b/site/src/cut/lib/store.test.ts
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, test } from "bun:test";
import { groupRemap } from "@donkeycut/effects-kit";
import { adoptTransitionFields, clipLen, deriveTransitionFields, docOverlays, getClipSpans, liftClipLooks, moveOverlayGroup, overlayLaneOrder, normalizeElementLanes, parkedTransitions, placeInRun, projectDuration, reanchorTransitions, separateOverlaps, serializeDoc, useEditor } from "./store";
-import { playheadAt, setPlayhead } from "./playhead";
+import { playheadAt, setPlayhead, setSkim } from "./playhead";
import { emptySubtitles } from "./types";
import type { AudioClip, MediaAsset, SubtitleCue, TextOverlay, VideoClip } from "./types";
@@ -87,6 +87,7 @@ const videoLane = (track: number) =>
.map((c) => ({ start: c.start, end: c.start + clipLen(c) }));
beforeEach(() => {
+ setSkim(null);
useEditor.setState({
clips: [],
transitions: [],
@@ -1020,6 +1021,32 @@ describe("bars and clip edges", () => {
expect(parkedTransitions(s().clips, s().transitions)).toEqual([]);
});
+ test("paste lands under the skimmer when one is live, sliding clear of the lane", () => {
+ const av = asset(8);
+ const a = vclip({ track: 0, start: 0, out: 3, assetId: av.id });
+ useEditor.setState({
+ assets: [av],
+ clips: [a],
+ selection: { kind: "clip", id: a.id },
+ multiSelection: [{ kind: "clip", id: a.id }],
+ });
+ expect(s().copySelection()).toBe(true);
+ setPlayhead(10);
+ setSkim(5);
+ expect(s().paste()).toBe(true);
+ // The skimmer wins over the playhead.
+ expect(s().clips.map((c) => c.start)).toEqual([0, 5]);
+ // A skim into occupied ground slides to the lane's next gap that fits.
+ setSkim(1);
+ expect(s().paste()).toBe(true);
+ expect(s().clips.map((c) => c.start)).toEqual([0, 5, 8]);
+ expectLaneSound(videoLane(0));
+ // With the pointer off the timeline, the playhead takes over.
+ setSkim(null);
+ expect(s().paste()).toBe(true);
+ expect(s().clips.map((c) => c.start)).toEqual([0, 5, 8, 11]);
+ });
+
test("an animation on a far edge leaves an unrelated transition alone", () => {
const av = asset(4);
const a = vclip({ track: 0, start: 0, out: 4, assetId: av.id });
diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.ts
index b3727d93..a89ce168 100644
--- a/site/src/cut/lib/store.ts
+++ b/site/src/cut/lib/store.ts
@@ -55,7 +55,7 @@ import {
import { renderMix, transcribeSamples, type CloudTranscribeSpec } from "./cloudTranscribe";
import { alignCues } from "./cueAlign";
import { useGenNotify } from "./genNotify";
-import { clampPlayhead, playheadAt, setPlayhead, setSkim } from "./playhead";
+import { clampPlayhead, playheadAt, previewAt, setPlayhead, setSkim } from "./playhead";
import { engineTranscribeSamples, withEngineStt } from "./localStt";
import { trackLocale } from "./subtitles";
import { ANIM_STYLE_IDS, animStyleOfTransition, clipPoseAt, emptySubtitles, frameOf, IMAGE_CLIP_SECONDS, isEffectOverlay, isStickerOverlay, MAX_SUBTITLE_LANES, mediaUrl, migrateBehindSubject, migrateLegacyTransitions, normalizeAspect, overlayAnimStyle, SPEED_FLOOR, SPEED_MIN, stampOverlayKinds, stripDefaultOverlayKinds, TRANSITION_MAX, TRANSITION_STYLE_IDS, transitionStyleOfAnim } from "./types";
@@ -538,8 +538,9 @@ export interface EditorState {
endHistoryBatch: () => void;
/** Copy the selected clip/audio/overlay/title(s) to the timeline clipboard. */
copySelection: () => boolean;
- /** Paste the clipboard at the playhead — sliding past anything already on
- * the target lane — and select the pasted item(s). */
+ /** Paste the clipboard at the preview time (the skimmer while one is live,
+ * the playhead otherwise) — sliding past anything already on the target
+ * lane — and select the pasted item(s). */
paste: () => boolean;
}
@@ -3976,7 +3977,9 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
)
return false;
push();
- const t = Math.max(0, playheadAt());
+ // The paste lands under the skimmer while one is live, at the playhead
+ // otherwise — the same moment the preview is showing.
+ const t = Math.max(0, previewAt());
const newSel: Selection[] = [];
set((cur) => {
let clips = cur.clips;
@@ -3989,7 +3992,7 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
// When clips ride the same paste, their transition bars follow them by
// this shift, so a copied sequence keeps its blends on its own cuts.
let clipDelta: number | null = null;
- // Every item aims for the playhead but respects what already sits on
+ // Every item aims for the paste point but respects what already sits on
// its lane: an occupied spot slides the paste right to the next gap
// that fits. Earlier items of this same paste count too.
for (const cb of clipboard) {
@@ -4033,8 +4036,8 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
// Transition bars land last, against the row as this paste left it.
// Bars copied together with clips keep their place in the copied
// sequence; a bar-only paste lands like a drop from the panel — onto
- // the boundary nearest the playhead when one is in reach (replacing
- // whatever played there), parked exactly at the playhead otherwise. A
+ // the boundary nearest the paste point when one is in reach (replacing
+ // whatever played there), parked exactly at the paste point otherwise. A
// multi-bar paste keeps the bars' spacing, anchored by the earliest.
const barItems = clipboard
.flatMap((cb) => (cb.kind === "transition" ? [cb.item] : []))