From affa0a38a9c3d725d896403d18eaec1158459898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 10 Aug 2026 15:52:41 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(timeline):=20a=20ripple-clos?= =?UTF-8?q?ed=20clip's=20head=20no=20longer=20overflows=20on=20grab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `trim_room` read a clip's head room as `start - in_frame`, which assumes a clip never carries more source in front of it than the timeline has room for. A ripple delete leaves exactly that: cut at 5, delete the first piece, and the survivor slides back to frame 0 still holding in-point 5. Grabbing its left edge then subtracted with overflow -- a panic in debug on every pointer sample of the drag, and a wrapped `lo` in release, which is a clamp that means nothing. Saturating, because frame 0 is the other wall that room was always bounded by: a head can be pulled back to the start of the timeline and no further, whatever the file still has behind it. --- crates/engine/src/project.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index ecfdbf9..f22d348 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1130,8 +1130,13 @@ impl Project { let (member_lo, member_hi) = match edge { Edge::Start => ( // Back to the source's own first frame, and never over the - // clip in front of it. - (c.start - c.in_frame).max(i.checked_sub(1).map_or(0, |p| clips[p].end())), + // clip in front of it. Saturating because a clip may hold + // *more* head than the timeline has room for -- a ripple + // delete slides a clip back to frame 0 with its in-point + // wherever the cut left it -- and frame 0 is the other wall. + c.start + .saturating_sub(c.in_frame) + .max(i.checked_sub(1).map_or(0, |p| clips[p].end())), c.end() - 1, ), Edge::End => ( @@ -2303,6 +2308,30 @@ mod tests { assert_eq!(shape(&p)[0][0], clip(4, 0, 4, 0), "one frame of head left"); } + /// A clip whose in-point is *past* its own start -- what a ripple delete + /// leaves, the piece in front of it gone and this one slid back to frame 0 + /// carrying the in-point the cut gave it. Its head has more source behind it + /// than the timeline has room for, and the timeline's own first frame is the + /// wall: asking is not an overflow, and the answer is 0. + #[test] + fn a_ripple_closed_clip_can_still_be_head_trimmed() { + let mut p = Project::single(FILE, 9); + assert!(p.split(5)); + assert!(p.delete_in(Lane::V1, 0), "the first piece goes"); + assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)], "start 0, in-point 5"); + + assert_eq!( + p.trim_room(Lane::V1, 0, Edge::Start, SRC), + Some((0, 3)), + "back to frame 0 at most, and one frame of clip always survives" + ); + assert!(!p.trim(Lane::V1, 0, Edge::Start, 0, SRC), "already there"); + assert!(p.trim(Lane::V1, 0, Edge::Start, 2, SRC)); + assert_eq!(shape(&p)[0], vec![clip(2, 7, 9, 0)], "the in-point followed"); + assert!(p.trim(Lane::V1, 0, Edge::Start, 0, SRC), "and back out"); + assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]); + } + /// Linked halves trim as one: a link is one span on however many lanes, so /// the sound follows the picture's edge -- and the tightest wall of the two /// is what stops both.