From 8bd7e0cec2640bd1fa3eb1332ded2d76142b6186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 10 Sep 2026 00:58:32 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(bench):=20a=20shadow=20that?= =?UTF-8?q?=20lies=20is=20a=20broken=20drag=20=E2=80=94=20clamp=20the=20la?= =?UTF-8?q?nding,=20keep=20the=20lane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/app/src/player/timeline_edit.rs | 16 +++++++++-- crates/app/src/timeline_math.rs | 38 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 3131334..1148fba 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -909,13 +909,23 @@ impl Player { .collect() }) .unwrap_or_default(); + // Staying on its own lane, the engine clamps the travel into the gap + // the clip sits in rather than refusing it, so the shadow rests where + // the release will: flush against the take it was dragged into. Landing + // on *another* lane it is refused outright when a take is already + // there, and the shadow says so before the hand lets go -- never a + // silent no-op. + let len = drag.clip.frames(); + let (start, refused) = match to == drag.lane { + true => (gap_clamp(drag.clip.start, len, start, &neighbours), false), + false => (start, collides(start, len, &neighbours)), + }; let anchor = Ghost { lane: to, start, - frames: drag.clip.frames(), + frames: len, tint: self.clip_tint(drag.clip.source), - refused: drag.lane.kind != to.kind - || collides(start, drag.clip.frames(), &neighbours), + refused: drag.lane.kind != to.kind || refused, }; let mut ghosts = vec![anchor]; if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 { diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index de6632b..6899da1 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -677,6 +677,29 @@ pub(crate) fn collides(start: u32, len: u32, others: &[(u32, u32)]) -> bool { .any(|&(other_start, other_end)| start < other_end && other_start < end) } +/// Where a clip staying on its own lane really comes to rest: `want`, clamped +/// into the gap it is sitting in -- the take behind it and the take in front of +/// it are walls ([`Project::move_selection`] clamps the delta by exactly these, +/// it does not refuse), so a clip dragged hard left past its neighbour lands +/// flush against that neighbour's tail rather than nowhere. `now` is its head +/// today, which is what names the gap. The shadow reads this, so the box drawn +/// in flight is the box the release leaves behind. +pub(crate) fn gap_clamp(now: u32, len: u32, want: u32, others: &[(u32, u32)]) -> u32 { + let lo = others + .iter() + .filter(|&&(_, end)| end <= now) + .map(|&(_, end)| end) + .max() + .unwrap_or(0); + let hi = others + .iter() + .filter(|&&(start, _)| start >= now.saturating_add(len)) + .map(|&(start, _)| start) + .min() + .unwrap_or(u32::MAX); + want.clamp(lo, hi.saturating_sub(len).max(lo)) +} + /// The lane a release lands on when the pointer is off the rows themselves: /// the row under it while its kind can hold what is in the hand, and otherwise /// the last one that could -- a picture clip carried down across A1 on its way @@ -891,6 +914,21 @@ mod drop_landing_tests { assert_eq!(held_lane(None, a1, v1), None); } + /// A clip dragged hard left past the take in front of it comes to rest + /// flush against that take -- the walls of its own gap, which is what the + /// engine clamps the drag by -- and one dragged off the head of the + /// timeline rests on frame 0. + #[test] + fn a_drag_past_a_neighbour_rests_flush_against_it() { + let others = [(0, 375), (900, 1000)]; + assert_eq!(gap_clamp(375, 500, 0, &others), 375, "flush with its tail"); + assert_eq!(gap_clamp(375, 500, 380, &others), 380, "room to spare"); + assert_eq!(gap_clamp(375, 500, 800, &others), 400, "flush with the next"); + // An empty lane clamps at the head of the timeline and nowhere else. + assert_eq!(gap_clamp(500, 100, 0, &[]), 0); + assert_eq!(gap_clamp(500, 100, 9_000, &[]), 9_000); + } + /// The refused state the shadow draws: a head let go on top of a take /// already on the lane, which the engine changes nothing for. Laid exactly /// against one -- what the magnet is for -- is not a collision.