Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: preserve overlay timing across cuts and transitions
Richie McIlroy4e89ffcf4773
diff --git a/apps/desktop-gpui/src/editor_clips.rs b/apps/desktop-gpui/src/editor_clips.rsindex d8cc2448c..1f16e2946 100644--- a/apps/desktop-gpui/src/editor_clips.rs+++ b/apps/desktop-gpui/src/editor_clips.rs@@ -187,6 +187,19 @@ fn ripple_track<T: TrackSegmentOps>(track: &mut [T], boundary: f64, shift: f64)}}+fn ripple_keyboard_track(+ track: &mut [cap_project::KeyboardTrackSegment],+ boundary: f64,+ shift: f64,+) {+ for segment in track {+ if segment.end <= boundary {+ continue;+ }+ segment.remap_times(|time| if time >= boundary { time + shift } else { time });+ }+}+/// `moveClip` (`ClipsSidebar.tsx:639-690`): reorder `timeline.segments`,/// remapping the transitions that survive and -- for each one that does not --/// rippling every other track across the boundary the removed overlap used to@@ -225,16 +238,16 @@ pub(crate) fn move_clip(.copied().unwrap_or(0.)+ effective.duration;+ let boundary = edits::effective_to_output(&timeline.hold_windows(), boundary);timeline.transitions.retain(|candidate| candidate.segment_index != transition.segment_index);- // The source ripples these seven tracks and no others (`:672-682`).ripple_track(&mut timeline.zoom_segments, boundary, effective.duration);ripple_track(&mut timeline.scene_segments, boundary, effective.duration);ripple_track(&mut timeline.mask_segments, boundary, effective.duration);ripple_track(&mut timeline.text_segments, boundary, effective.duration);ripple_track(&mut timeline.caption_segments, boundary, effective.duration);- ripple_track(+ ripple_keyboard_track(&mut timeline.keyboard_segments,boundary,effective.duration,@@ -3791,12 +3804,57 @@ mod tests {edge_snap_ratio: 0.25,}];+ config.text_segments = serde_json::from_value(serde_json::json!([{+ "start": 10.0,+ "end": 12.0,+ "track": 0,+ "content": "Hold",+ "layout": "fullscreen"+ }]))+ .unwrap();+ config.keyboard_segments = serde_json::from_value(serde_json::json!([+ {+ "id": "before-boundary",+ "start": 11.0,+ "end": 12.0,+ "displayText": "a",+ "keys": [{ "key": "a", "timeOffset": 500.0 }]+ },+ {+ "id": "spanning-boundary",+ "start": 11.0,+ "end": 13.0,+ "displayText": "bc",+ "keys": [+ { "key": "b", "timeOffset": 500.0 },+ { "key": "c", "timeOffset": 1500.0 }+ ]+ }+ ]))+ .unwrap();// Moving clip 0 to the end separates the 0|1 pair, dropping the 1s// transition whose boundary sat at offset(1) + 1.0 = 10.0.assert!(move_clip(&mut config, 0, 3));assert!(config.transitions.is_empty());assert_eq!(config.zoom_segments[0].start, 16.0);assert_eq!(config.zoom_segments[0].end, 19.0);+ assert_eq!(+ (+ config.keyboard_segments[0].start,+ config.keyboard_segments[0].end,+ config.keyboard_segments[0].keys[0].time_offset,+ ),+ (11.0, 12.0, 500.0)+ );+ assert_eq!(+ (+ config.keyboard_segments[1].start,+ config.keyboard_segments[1].end,+ ),+ (11.0, 14.0)+ );+ assert_eq!(config.keyboard_segments[1].keys[0].time_offset, 500.0);+ assert_eq!(config.keyboard_segments[1].keys[1].time_offset, 2500.0);}/// `computeDropIndex` (`:692-703`): the insertion point is after everydiff --git a/apps/desktop-gpui/src/editor_edits.rs b/apps/desktop-gpui/src/editor_edits.rsindex 5dc89489a..5cf07c933 100644--- a/apps/desktop-gpui/src/editor_edits.rs+++ b/apps/desktop-gpui/src/editor_edits.rs@@ -548,11 +548,10 @@ impl TrackSegmentOps for KeyboardTrackSegment {fn set_end(&mut self, value: f64) {self.end = value;}- /// `id: \`kb-split-${Date.now()}-${random}\`` (`ED/context.ts:983`).fn split_tail(&self, at: f64) -> Self {let mut tail = self.clone();tail.start = self.start + at;- tail.id = split_id("kb");+ tail.id = split_id("kb-edit");tail}}@@ -911,11 +910,18 @@ pub fn delete_clip_segments(timeline: &mut TimelineConfiguration, indices: &[usilet Some(segment) = timeline.segments.get(index) else {continue;};- let cut_start = offsets.get(index).copied().unwrap_or(0.0);- let cut_end = cut_start + segment.duration();+ let clip_start = offsets.get(index).copied().unwrap_or(0.0);+ let incoming_transition = timeline+ .effective_transition(index)+ .map_or(0.0, |transition| transition.duration);+ let outgoing_transition = timeline+ .effective_transition(index + 1)+ .map_or(0.0, |transition| transition.duration);+ let cut_start = clip_start + incoming_transition;+ let cut_end = clip_start + segment.duration() - outgoing_transition;let holds = timeline.hold_windows();- let output_cut_start = effective_to_output(&holds, cut_start, false);- let output_cut_end = effective_to_output(&holds, cut_end, true);+ let output_cut_start = effective_to_output_end(&holds, cut_start);+ let output_cut_end = effective_to_output_end(&holds, cut_end);let duration_before = clip_timeline_duration(timeline);timeline.segments.remove(index);@@ -944,10 +950,22 @@ pub fn delete_clip_segments(timeline: &mut TimelineConfiguration, indices: &[usideleted}-fn effective_to_output(holds: &[(f64, f64)], effective: f64, end: bool) -> f64 {+pub(crate) fn effective_to_output_end(holds: &[(f64, f64)], effective: f64) -> f64 {let mut output = effective;for (start, finish) in holds {- if output > *start || (!end && output == *start) {+ if output > *start {+ output += finish - start;+ } else {+ break;+ }+ }+ output+}++pub(crate) fn effective_to_output(holds: &[(f64, f64)], effective: f64) -> f64 {+ let mut output = effective;+ for (start, finish) in holds {+ if output >= *start {output += finish - start;} else {break;@@ -992,7 +1010,8 @@ fn ripple_deleted_bounds(} else if start < cut_start {(start, cut_start)} else {- (cut_start, (end - shift).max(cut_start))+ let start = cut_end - shift;+ (start, (end - shift).max(start))};(end > start).then_some((start, end))}@@ -1079,22 +1098,116 @@ fn ripple_delete_camera3d_track(shift: f64,) {segments.retain_mut(|segment| {- let old_duration = segment.end - segment.start;+ let old_start = segment.start;+ let old_end = segment.end;+ if old_end <= cut_start {+ return true;+ }+ if old_start >= cut_end {+ segment.start -= shift;+ segment.end -= shift;+ return true;+ }+ if old_start >= cut_start && old_end <= cut_end {+ return false;+ }let Some((new_start, new_end)) =- ripple_deleted_bounds(segment.start, segment.end, cut_start, cut_end, shift)+ ripple_deleted_bounds(old_start, old_end, cut_start, cut_end, shift)else {return false;};+ let retains_left = old_start < cut_start;+ let retains_right = old_end > cut_end;+ let ripple = Camera3DRipple {+ old_start,+ new_start,+ cut_start,+ cut_end,+ shift,+ retains_left,+ retains_right,+ };+ for track in segment.tracks.all_tracks_mut() {+ ripple_camera3d_keyframes(track, ripple);+ }+ if retains_left && !retains_right {+ segment.transition_out = 0.0;+ } else if !retains_left && retains_right {+ segment.transition_in = 0.0;+ }segment.start = new_start;segment.end = new_end;- let new_duration = new_end - new_start;- if old_duration > 0.0 && (new_duration - old_duration).abs() > f64::EPSILON {- scale_keyframe_times(&mut segment.tracks, new_duration / old_duration);- }true});}+#[derive(Clone, Copy)]+struct Camera3DRipple {+ old_start: f64,+ new_start: f64,+ cut_start: f64,+ cut_end: f64,+ shift: f64,+ retains_left: bool,+ retains_right: bool,+}++fn ripple_camera3d_keyframes(+ keyframes: &mut Vec<cap_project::Camera3DKeyframe>,+ ripple: Camera3DRipple,+) {+ if keyframes.is_empty() {+ return;+ }+ let mut old = std::mem::take(keyframes);+ old.sort_by(|left, right| left.time.total_cmp(&right.time));+ let cut_start_local = ripple.cut_start - ripple.old_start;+ let cut_end_local = ripple.cut_end - ripple.old_start;+ let boundary = |time: f64, left: bool| {+ let previous = old.iter().rev().find(|keyframe| keyframe.time <= time);+ let next = old.iter().find(|keyframe| keyframe.time >= time);+ cap_project::Camera3DKeyframe {+ time,+ value: cap_rendering::camera3d::sample_track(0.0, &old, time),+ out_easing: if left {+ None+ } else {+ previous.and_then(|keyframe| keyframe.out_easing)+ },+ in_easing: if left {+ next.and_then(|keyframe| keyframe.in_easing)+ } else {+ None+ },+ }+ };++ keyframes.extend(+ old.iter()+ .filter(|keyframe| ripple.old_start + keyframe.time < ripple.cut_start)+ .cloned(),+ );+ if ripple.retains_left {+ let mut keyframe = boundary(cut_start_local, true);+ keyframe.time = ripple.cut_start - ripple.new_start;+ keyframes.push(keyframe);+ }+ if ripple.retains_right {+ let mut keyframe = boundary(cut_end_local, false);+ keyframe.time = ripple.cut_end - ripple.shift - ripple.new_start;+ keyframes.push(keyframe);+ }+ keyframes.extend(+ old.into_iter()+ .filter(|keyframe| ripple.old_start + keyframe.time > ripple.cut_end)+ .map(|mut keyframe| {+ keyframe.time = ripple.old_start + keyframe.time - ripple.shift - ripple.new_start;+ keyframe+ }),+ );+ keyframes.sort_by(|left, right| left.time.total_cmp(&right.time));+}+fn ripple_delete_audio_track(segments: &mut Vec<AudioTrackSegment>,cut_start: f64,@@ -1116,7 +1229,7 @@ fn ripple_delete_audio_track(let old_start = tail.start;segment.end = cut_start;segment.fade_out = 0.0;- tail.start = cut_start;+ tail.start = cut_end - shift;tail.end -= shift;tail.trim_start += cut_end - old_start;tail.fade_in = 0.0;@@ -1130,8 +1243,8 @@ fn ripple_delete_audio_track(next.push(segment);} else {let old_start = segment.start;- segment.start = cut_start;- segment.end = (segment.end - shift).max(cut_start);+ segment.start = cut_end - shift;+ segment.end = (segment.end - shift).max(segment.start);segment.trim_start += cut_end - old_start;segment.fade_in = 0.0;if segment.end > segment.start {@@ -1185,7 +1298,7 @@ pub fn split_segment(let Some((head, mut tail)) = segment.split_at(segment.start + at) else {return false;};- tail.id = split_id("kb");+ tail.id = split_id("kb-edit");timeline.keyboard_segments[index] = head;timeline.keyboard_segments.insert(index + 1, tail);return true;@@ -2777,6 +2890,7 @@ mod tests {assert_eq!(left.keys[0].time_offset, 500.0);assert_eq!(right.keys[0].time_offset, 500.0);assert_ne!(left.id, right.id);+ assert!(right.id.starts_with("kb-edit-split-"));}#[test]@@ -3012,6 +3126,76 @@ mod tests {assert_eq!(keyboard.keys[1].time_offset, 1500.0);}+ #[test]+ fn deleting_a_clip_preserves_transition_overlaps_and_boundary_holds() {+ let mut project = config(serde_json::json!({+ "timeline": {+ "segments": [+ { "recordingSegment": 0, "timescale": 1.0, "start": 0.0, "end": 10.0 },+ { "recordingSegment": 1, "timescale": 1.0, "start": 0.0, "end": 10.0 },+ { "recordingSegment": 2, "timescale": 1.0, "start": 0.0, "end": 10.0 }+ ],+ "transitions": [+ { "segmentIndex": 1, "type": "cross-fade", "duration": 1.0 },+ { "segmentIndex": 2, "type": "cross-fade", "duration": 1.0 }+ ],+ "zoomSegments": [],+ "textSegments": [+ { "start": 10.0, "end": 12.0, "track": 0, "content": "removed", "layout": "fullscreen" },+ { "start": 20.0, "end": 22.0, "track": 0, "content": "retained", "layout": "fullscreen" }+ ],+ "keyboardSegments": [+ {+ "id": "left-overlap", "start": 9.0, "end": 10.0,+ "displayText": "a", "keys": [{ "key": "a", "timeOffset": 500.0 }]+ },+ {+ "id": "right-overlap", "start": 20.0, "end": 21.0,+ "displayText": "b", "keys": [{ "key": "b", "timeOffset": 500.0 }]+ }+ ],+ "audioSegments": [{+ "start": 15.0, "end": 23.0, "track": 0, "path": "/tmp/a.mp3",+ "trimStart": 4.0+ }]+ }+ }));+ let timeline = project.timeline.as_mut().unwrap();++ assert!(delete_clip_segments(timeline, &[1]));++ assert!(timeline.transitions.is_empty());+ assert_eq!(timeline.text_segments.len(), 1);+ assert_eq!(+ (+ timeline.text_segments[0].start,+ timeline.text_segments[0].end+ ),+ (10.0, 12.0)+ );+ assert_eq!(+ (+ timeline.keyboard_segments[0].start,+ timeline.keyboard_segments[0].end,+ timeline.keyboard_segments[0].keys[0].time_offset,+ ),+ (9.0, 10.0, 500.0)+ );+ assert_eq!(+ (+ timeline.keyboard_segments[1].start,+ timeline.keyboard_segments[1].end,+ timeline.keyboard_segments[1].keys[0].time_offset,+ ),+ (10.0, 11.0, 500.0)+ );+ let audio = &timeline.audio_segments[0];+ assert_eq!(+ (audio.start, audio.end, audio.trim_start),+ (10.0, 13.0, 9.0)+ );+ }+#[test]fn output_ripple_preserves_audio_and_keyframe_payload_alignment() {let mut project = two_clip_config();@@ -3077,6 +3261,68 @@ mod tests {assert_eq!(audio.trim_start, 11.5);}+ #[test]+ fn camera3d_ripple_drops_cut_keys_and_preserves_both_boundary_poses() {+ let mut camera = default_camera3d_segment(0.0, 10.0);+ camera.tracks.tilt_x = [2.0, 5.0, 8.0]+ .into_iter()+ .map(|time| cap_project::Camera3DKeyframe {+ time,+ value: time,+ out_easing: Some([0.0, 0.0]),+ in_easing: Some([1.0, 1.0]),+ })+ .collect();+ let old_track = camera.tracks.tilt_x.clone();+ let mut segments = vec![camera];++ ripple_delete_camera3d_track(&mut segments, 3.0, 6.0, 3.0);++ let camera = &segments[0];+ assert_eq!((camera.start, camera.end), (0.0, 7.0));+ let track = &camera.tracks.tilt_x;+ assert_eq!(+ track+ .iter()+ .map(|keyframe| (keyframe.time, keyframe.value))+ .collect::<Vec<_>>(),+ vec![(2.0, 2.0), (3.0, 3.0), (3.0, 6.0), (5.0, 8.0)]+ );+ assert_eq!(track[1].in_easing, Some([1.0, 1.0]));+ assert_eq!(track[1].out_easing, None);+ assert_eq!(track[2].in_easing, None);+ assert_eq!(track[2].out_easing, Some([0.0, 0.0]));+ assert_eq!(+ cap_rendering::camera3d::sample_track(0.0, track, 2.5),+ cap_rendering::camera3d::sample_track(0.0, &old_track, 2.5)+ );+ let after_join = cap_rendering::camera3d::sample_track(0.0, track, 3.001);+ let before_cut = cap_rendering::camera3d::sample_track(0.0, &old_track, 6.001);+ assert!((after_join - before_cut).abs() < 1e-9);+ }++ #[test]+ fn ripple_right_tails_start_at_the_mapped_cut_end() {+ assert_eq!(+ ripple_deleted_bounds(4.0, 8.0, 3.0, 6.0, 2.0),+ Some((4.0, 6.0))+ );+ let mut audio = vec![default_audio_segment(+ 4.0,+ 8.0,+ 0,+ "content/audio/test.wav".into(),+ "Test".into(),+ Some(10.0),+ )];+ audio[0].trim_start = 1.0;++ ripple_delete_audio_track(&mut audio, 3.0, 6.0, 2.0);++ assert_eq!((audio[0].start, audio[0].end), (4.0, 6.0));+ assert_eq!(audio[0].trim_start, 3.0);+ }+#[test]fn deleting_a_masks_only_lane_renumbers_the_lanes_above_it() {let mut config = config(serde_json::json!({diff --git a/apps/desktop/src/routes/editor/keyboard-timing.test.ts b/apps/desktop/src/routes/editor/keyboard-timing.test.tsindex 2b681f50c..bcf37402e 100644--- a/apps/desktop/src/routes/editor/keyboard-timing.test.ts+++ b/apps/desktop/src/routes/editor/keyboard-timing.test.ts@@ -14,6 +14,7 @@ import { defaultCamera3DTracks } from "./three-d";import {deleteClipAndRippleAllTracks,rippleDeleteAllTracks,+ rippleDeleteFromTrack,} from "./timeline-utils";function keyboardSegment(@@ -101,6 +102,33 @@ describe("keyboard output timing", () => {});});+ it("leaves a keyboard segment ending at a transition boundary unchanged", () => {+ const segments = [keyboardSegment(4, 5, "a", [0])];++ rippleKeyboardTrack(segments, 5, -1);++ expect(segments[0]).toMatchObject({+ start: 4,+ end: 5,+ keys: [{ timeOffset: 0 }],+ });+ });++ it("maps a retained right tail to the shifted cut end", () => {+ const segments = [keyboardSegment(5.5, 8, "a", [500])];+ const overlays = [{ start: 5.5, end: 8 }];++ rippleDeleteKeyboardTrack(segments, 5, 6, 0.5);+ rippleDeleteFromTrack(overlays, 5, 6, 0.5);++ expect(segments[0]).toMatchObject({+ start: 5.5,+ end: 7.5,+ keys: [{ timeOffset: 0 }],+ });+ expect(overlays).toEqual([{ start: 5.5, end: 7.5 }]);+ });+it("whole-clip deletion removes holds and uses the actual transition duration", () => {const timeline = {segments: [@@ -113,10 +141,11 @@ describe("keyboard output timing", () => {{ segmentIndex: 2, type: "cross-fade" as const, duration: 1 },],textSegments: [- { start: 4, end: 6, enabled: true, layout: "fullscreen" as const },+ { start: 4, end: 5, enabled: true, layout: "fullscreen" as const },+ { start: 7, end: 8, enabled: true, layout: "fullscreen" as const },],zoomSegments: [{ start: 10, end: 11 }],- keyboardSegments: [keyboardSegment(10, 11, "a", [250])],+ keyboardSegments: [keyboardSegment(3, 9, "abc", [500, 2500, 5500])],audioSegments: [{ start: 5, end: 10, trimStart: 2, fadeIn: 1 }],maskSegments: [{@@ -143,29 +172,85 @@ describe("keyboard output timing", () => {expect(deleteClipAndRippleAllTracks(timeline, 1)).toBe(true);expect(timeline.segments).toHaveLength(2);expect(timeline.transitions).toEqual([]);- expect(timeline.textSegments).toEqual([]);- expect(timeline.zoomSegments).toEqual([{ start: 6, end: 7 }]);+ expect(timeline.textSegments).toEqual([+ { start: 4, end: 5, enabled: true, layout: "fullscreen" },+ ]);+ expect(timeline.zoomSegments).toEqual([{ start: 7, end: 8 }]);expect(timeline.keyboardSegments[0]).toMatchObject({- start: 6,- end: 7,- keys: [{ timeOffset: 250 }],+ start: 3,+ end: 6,+ displayText: "ac",+ keys: [{ timeOffset: 500 }, { timeOffset: 2500 }],});expect(timeline.audioSegments).toEqual([- { start: 3, end: 6, trimStart: 6, fadeIn: 0 },+ { start: 4, end: 7, trimStart: 4, fadeIn: 0 },]);expect(timeline.maskSegments[0]).toMatchObject({- start: 3,- end: 6,+ start: 4,+ end: 7,keyframes: { position: [{ time: 2 }, { time: 2.5 }] },});expect(timeline.camera3dSegments).toHaveLength(1);expect(timeline.camera3dSegments[0]).toMatchObject({- start: 6,- end: 10,+ start: 7,+ end: 11,tracks: { zoom: [{ time: 2, value: 1 }] },});});+ it("cuts camera keyframes without rescaling retained source timing", () => {+ const tracks = defaultCamera3DTracks();+ tracks.zoom = [+ {+ time: 2,+ value: 2,+ outEasing: [0, 0],+ inEasing: null,+ },+ {+ time: 5,+ value: 5,+ outEasing: [0, 0],+ inEasing: [1, 1],+ },+ {+ time: 8,+ value: 8,+ outEasing: null,+ inEasing: [1, 1],+ },+ ];+ const timeline = {+ segments: [{ start: 0, end: 10, timescale: 1 }],+ camera3dSegments: [+ {+ start: 0,+ end: 10,+ tracks,+ transitionIn: 0.2,+ transitionOut: 0.3,+ },+ ],+ };++ rippleDeleteAllTracks(timeline, 3, 6);++ expect(timeline.camera3dSegments[0]).toMatchObject({+ start: 0,+ end: 7,+ transitionIn: 0.2,+ transitionOut: 0.3,+ tracks: {+ zoom: [+ { time: 2, value: 2, outEasing: [0, 0], inEasing: null },+ { time: 3, value: 3, outEasing: null, inEasing: [1, 1] },+ { time: 3, value: 6, outEasing: [0, 0], inEasing: null },+ { time: 5, value: 8, outEasing: null, inEasing: [1, 1] },+ ],+ },+ });+ });+it("retains the last clip", () => {const timeline = {segments: [{ start: 0, end: 4, timescale: 1 }],@@ -185,19 +270,24 @@ describe("keyboard output timing", () => {const generated = keyboardSegment(10, 13, "abc", [0, 1000, 2000]);const generatedParts = splitKeyboardSegment(generated, 11, "keyboard-2");expect(generatedParts?.[0]).toMatchObject({+ id: "kb-edit-keyboard-1",end: 11,displayText: "a",keys: [{ timeOffset: 0 }],});expect(generatedParts?.[1]).toMatchObject({- id: "keyboard-2",+ id: "kb-edit-keyboard-2",start: 11,displayText: "bc",keys: [{ timeOffset: 0 }, { timeOffset: 1000 }],});const manual = keyboardSegment(10, 13, "Custom", []);- const manualParts = splitKeyboardSegment(manual, 11, "keyboard-3");+ const manualParts = splitKeyboardSegment(manual, 11, "kb-edit-keyboard-3");+ expect(manualParts?.map((part) => part.id)).toEqual([+ "kb-edit-keyboard-1",+ "kb-edit-keyboard-3",+ ]);expect(manualParts?.map((part) => part.displayText)).toEqual(["Custom","Custom",diff --git a/apps/desktop/src/routes/editor/keyboard-timing.ts b/apps/desktop/src/routes/editor/keyboard-timing.tsindex 1d5530a78..cd1c18fe6 100644--- a/apps/desktop/src/routes/editor/keyboard-timing.ts+++ b/apps/desktop/src/routes/editor/keyboard-timing.ts@@ -50,9 +50,12 @@ export function rippleKeyboardTrack(boundary: number,shift: number,) {- mapKeyboardTrackTimes(segments, (time) =>- time >= boundary ? time + shift : time,- );+ for (const segment of segments) {+ if (segment.end <= boundary) continue;+ rebaseKeys(segment, segment.start, (time) =>+ time >= boundary ? time + shift : time,+ );+ }}export function rippleDeleteKeyboardTrack(@@ -98,7 +101,7 @@ export function rippleDeleteKeyboardTrack(} else if (segment.start < cutStart) {segment.end = cutStart;} else {- segment.start = cutStart;+ segment.start = cutEnd - shift;segment.end = Math.max(segment.start, segment.end - shift);}@@ -130,8 +133,9 @@ export function splitKeyboardSegment(const left = structuredClone(segment);const right = structuredClone(segment);+ if (!left.id.startsWith("kb-edit-")) left.id = `kb-edit-${left.id}`;left.end = at;- right.id = rightId;+ right.id = rightId.startsWith("kb-edit-") ? rightId : `kb-edit-${rightId}`;right.start = at;if (!segment.keys?.length) return [left, right];diff --git a/apps/desktop/src/routes/editor/timeline-utils.ts b/apps/desktop/src/routes/editor/timeline-utils.tsindex 167b424c2..dd82410ed 100644--- a/apps/desktop/src/routes/editor/timeline-utils.ts+++ b/apps/desktop/src/routes/editor/timeline-utils.ts@@ -4,11 +4,16 @@ import {clipDuration,clipTimelineDuration,clipTimelineOffsets,+ getClipTransition,transitionsAfterClipDelete,transitionsAfterClipSplit,} from "./clip-transitions";import { rippleDeleteKeyboardTrack } from "./keyboard-timing";-import { type Camera3DTracks, scaleKeyframeTimes } from "./three-d";+import {+ CAMERA3D_TRACK_KEYS,+ type Camera3DTracks,+ sampleTrack,+} from "./three-d";import {effectiveToOutput,effectiveToOutputEnd,@@ -69,7 +74,7 @@ export function rippleDeleteFromTrack(} else if (seg.start < cutStart) {seg.end = cutStart;} else {- seg.start = cutStart;+ seg.start = cutEnd - shiftDuration;seg.end = Math.max(seg.start, seg.end - shiftDuration);}}@@ -140,6 +145,105 @@ function rippleDeleteAudioTrack(rippleDeleteFromTrack(segments, cutStart, cutEnd, shift);}+type RippleCamera3DSegment = {+ start: number;+ end: number;+ tracks: Camera3DTracks;+ transitionIn?: number;+ transitionOut?: number;+};++function rippleDeleteCamera3DTrack(+ segments: RippleCamera3DSegment[],+ cutStart: number,+ cutEnd: number,+ shift: number,+) {+ for (+ let segmentIndex = segments.length - 1;+ segmentIndex >= 0;+ segmentIndex--+ ) {+ const segment = segments[segmentIndex];+ if (segment.end <= cutStart) continue;+ if (segment.start >= cutEnd) {+ segment.start -= shift;+ segment.end -= shift;+ continue;+ }+ if (segment.start >= cutStart && segment.end <= cutEnd) {+ segments.splice(segmentIndex, 1);+ continue;+ }++ const oldStart = segment.start;+ const oldEnd = segment.end;+ const keepsLeft = oldStart < cutStart;+ const keepsRight = oldEnd > cutEnd;+ const newStart = keepsLeft ? oldStart : cutEnd - shift;+ const newEnd = keepsRight ? oldEnd - shift : cutStart;+ const leftCutTime = cutStart - oldStart;+ const rightCutTime = cutEnd - oldStart;++ for (const trackKey of CAMERA3D_TRACK_KEYS) {+ const keyframes = segment.tracks[trackKey];+ if (keyframes.length === 0) continue;+ const before = keepsLeft+ ? keyframes+ .filter((keyframe) => keyframe.time < leftCutTime)+ .map((keyframe) => ({ ...keyframe }))+ : [];+ const after = keepsRight+ ? keyframes+ .filter((keyframe) => keyframe.time > rightCutTime)+ .map((keyframe) => ({+ ...keyframe,+ time: oldStart + keyframe.time - shift - newStart,+ }))+ : [];+ const nextKeyframe = keyframes.find(+ (keyframe) => keyframe.time >= leftCutTime,+ );+ const previousKeyframe = [...keyframes]+ .reverse()+ .find((keyframe) => keyframe.time <= rightCutTime);+ segment.tracks[trackKey] = [+ ...before,+ ...(keepsLeft+ ? [+ {+ time: cutStart - newStart,+ value: sampleTrack(0, keyframes, leftCutTime),+ outEasing: null,+ inEasing: nextKeyframe?.inEasing ?? null,+ },+ ]+ : []),+ ...(keepsRight+ ? [+ {+ time: cutEnd - shift - newStart,+ value: sampleTrack(0, keyframes, rightCutTime),+ outEasing: previousKeyframe?.outEasing ?? null,+ inEasing: null,+ },+ ]+ : []),+ ...after,+ ];+ }++ segment.start = newStart;+ segment.end = Math.max(newStart, newEnd);+ if (keepsLeft && !keepsRight && segment.transitionOut !== undefined) {+ segment.transitionOut = 0;+ }+ if (!keepsLeft && keepsRight && segment.transitionIn !== undefined) {+ segment.transitionIn = 0;+ }+ }+}+export function cutClipSegmentsForRange(segments: Array<{timescale: number;@@ -231,15 +335,16 @@ export function rippleDeleteAllTracks(captionSegments?: Array<{ start: number; end: number }> | null;keyboardSegments?: KeyboardTrackSegment[] | null;audioSegments?: RippleAudioSegment[] | null;- camera3dSegments?: Array<{- start: number;- end: number;- tracks: Camera3DTracks;- }> | null;+ camera3dSegments?: RippleCamera3DSegment[] | null;},cutStart: number,cutEnd: number,requestedSegmentIndex?: number,+ trackCutRange?: {+ start: number;+ end: number;+ removeHoldAtStart?: boolean;+ },) {// The clip cut below works in the gapless recording-flow domain, but the// overlay tracks live in output time, which includes fullscreen-text@@ -247,8 +352,12 @@ export function rippleDeleteAllTracks(// time inside the cut leave with the text segments it belongs to (they// sit inside the converted range, so the overlay pass deletes them).const holds = holdWindows(timeline.textSegments);- const overlayCutStart = effectiveToOutput(holds, cutStart);- const overlayCutEnd = effectiveToOutputEnd(holds, cutEnd);+ const trackCutStart = trackCutRange?.start ?? cutStart;+ const trackCutEnd = trackCutRange?.end ?? cutEnd;+ const overlayCutStart = trackCutRange?.removeHoldAtStart+ ? effectiveToOutputEnd(holds, trackCutStart)+ : effectiveToOutput(holds, trackCutStart);+ const overlayCutEnd = effectiveToOutputEnd(holds, trackCutEnd);const durationBefore = clipTimelineDuration(timeline.segments,@@ -295,7 +404,8 @@ export function rippleDeleteAllTracks(durationBefore - clipTimelineDuration(timeline.segments, nextTransitions),);const overlayShift =- shiftDuration + (overlayCutEnd - overlayCutStart - (cutEnd - cutStart));+ shiftDuration ++ (overlayCutEnd - overlayCutStart - (trackCutEnd - trackCutStart));if (timeline.zoomSegments)rippleDeleteFromTrack(timeline.zoomSegments,@@ -346,25 +456,12 @@ export function rippleDeleteAllTracks(overlayShift,);if (timeline.camera3dSegments) {- const previousDurations = new Map(- timeline.camera3dSegments.map((segment) => [- segment,- segment.end - segment.start,- ]),- );- rippleDeleteFromTrack(+ rippleDeleteCamera3DTrack(timeline.camera3dSegments,overlayCutStart,overlayCutEnd,overlayShift,);- for (const segment of timeline.camera3dSegments) {- const previousDuration = previousDurations.get(segment);- if (previousDuration === undefined) continue;- const nextDuration = segment.end - segment.start;- if (previousDuration <= 0 || previousDuration === nextDuration) continue;- scaleKeyframeTimes(segment.tracks, nextDuration / previousDuration);- }}}@@ -378,12 +475,24 @@ export function deleteClipAndRippleAllTracks(timeline.segments,timeline.transitions ?? [],)[segmentIndex];- rippleDeleteAllTracks(- timeline,- start,- start + clipDuration(segment),- segmentIndex,- );+ const incomingDuration =+ getClipTransition(+ timeline.segments,+ timeline.transitions ?? [],+ segmentIndex,+ )?.duration ?? 0;+ const outgoingDuration =+ getClipTransition(+ timeline.segments,+ timeline.transitions ?? [],+ segmentIndex + 1,+ )?.duration ?? 0;+ const end = start + clipDuration(segment);+ rippleDeleteAllTracks(timeline, start, end, segmentIndex, {+ start: start + incomingDuration,+ end: end - outgoingDuration,+ removeHoldAtStart: true,+ });return true;}