diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 1148fba..834dfd3 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -399,6 +399,10 @@ impl Player { self.selected.clear(); } self.reset_after_reseek(); + // The strip names the edit that just happened: a move that + // lands silently leaves the last word (`SPLIT`) standing, and + // an editor reads that as the drag having done nothing. + self.notify_user("MOVED".into()); } // The three ways a drag is refused, told apart by what the // front-end already knows: a lane's kind, and where the clip was. @@ -431,6 +435,9 @@ impl Player { .into(), ), } + // The gesture is over: the lane it ended over is nobody's answer any + // more (`Player::drag_lane`, read by `bench-content`'s catch-all). + self.drag_lane = None; cx.notify(); } @@ -802,7 +809,7 @@ impl Player { /// Where a clip let go at window `x` over lane `to` wants its head: the /// frame under the pointer, less however far into the box the hand grabbed /// it (so the clip does not jump under the pointer), pulled onto a - /// neighbouring edge when it lands within [`SNAP_PX`] of one. `None` when + /// neighbouring edge when it lands within [`Player::drop_snap_frames`] of one. `None` when /// there is no such clip to move. The engine has the last word on where it /// may actually go -- this is the ask, not the answer. /// @@ -912,13 +919,17 @@ impl Player { // 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. + // on *another* lane it clamps too ([`cross_room`], the engine's own + // `move_room` rule) and refuses only a head let go *inside* a take or a + // gap too narrow to hold the clip -- the shadow says so before the hand + // lets go, and never claims a refusal the release would not make. 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)), + false => match cross_room(start, len, &neighbours) { + Some(landed) => (landed, false), + None => (start, true), + }, }; let anchor = Ghost { lane: to, @@ -1178,9 +1189,6 @@ impl Player { } } - /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the bed's - /// own width drops out of it, since a pixel is now worth the same stretch of - /// timeline wherever the view sits. /// Whether the magnet is on for the gesture happening *now*: the switch /// ([`Player::snap`]) unless `alt` is held ([`Player::drag_alt`]), which /// turns it off for this drag or trim alone -- the temporary override @@ -1192,6 +1200,10 @@ impl Player { snap_live(self.snap, self.drag_alt) } + /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the + /// bed's own width drops out of it, since a pixel is now worth the same + /// stretch of timeline wherever the view sits. The edge trims' magnet -- + /// a drop asks [`Player::drop_snap_frames`]. pub(crate) fn snap_frames(&self) -> u32 { self.scale.snap_frames(self.fps) } diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index d104c03..977b6bb 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -1672,7 +1672,10 @@ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() { let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)]; let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps), None); let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps); - let (at, cue) = landing(under, 0, 0, true, scale.snap_frames(fps), &marks); + // The drop's own magnet, not the trims' finer one -- `Player::place_frame` + // ships `drop_snap_frames`, and a test computing with `snap_frames` stops + // mirroring production the moment the two differ. + let (at, cue) = landing(under, 0, 0, true, scale.drop_snap_frames(fps), &marks); assert_eq!((at, cue), (300, None), "the pointer is on frame 300"); // ...and what the release does with it: the frame back through the same diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index e0a32d8..1c048d9 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -3072,7 +3072,7 @@ fn the_bench_seam_stops_at_its_floor_and_its_ceiling() { /// DESIGN §7: "lanes scroll behind the pinned ruler and track heads" -- pinned /// means pinned. A clip that starts left of the view sits at a negative `left` /// inside its bed, and with no clip mask gpui paints it (and its hitbox) over -/// the 72 px head column, so V1/A1 and their verbs disappear under the first +/// the `HEAD_W` px head column, so V1/A1 and their verbs disappear under the first /// take as soon as the bench is wheeled past frame 0. The mask belongs on the /// bed itself so a half-scrolled clip still drags on the half that shows. #[test] diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index 6899da1..b258332 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -661,20 +661,33 @@ pub(crate) fn landing( snap_cue(on, under.saturating_sub(grab), len, tol, marks) } -/// Whether a clip `len` frames long landing at `start` would sit on top of one -/// of `others` -- `(start, end)` of every clip already on the lane it is being -/// let go over, less the ones travelling with it. The engine refuses such a -/// drop ([`Project::move_selection`]'s `move_room`), so the shadow is drawn as -/// refused rather than promising a landing the release will not make: a drag -/// that ends in nothing at all is what an editor reads as a broken timeline. +/// Where a clip `len` frames long, let go over *another* lane with its head +/// asked at `at`, really comes to rest -- `None` when the engine refuses the +/// drop outright. A mirror of [`Project::move_room`]: the release is refused +/// only when the asked head sits *inside* a take already there (a clamp has no +/// answer for that), or when the gap it names is narrower than the clip; +/// otherwise the head is clamped into that gap exactly as a same-lane move is +/// ([`gap_clamp`]). `others` is `(start, end)` of every clip already on the +/// destination lane, less the ones travelling with this one. /// -/// Touching is not overlapping -- a clip laid exactly against the take in front -/// of it is the whole point of the magnet. -pub(crate) fn collides(start: u32, len: u32, others: &[(u32, u32)]) -> bool { - let end = start.saturating_add(len); - others - .iter() - .any(|&(other_start, other_end)| start < other_end && other_start < end) +/// The shadow reads this, so a landing the release *will* make is never drawn +/// as refused -- a whole-span overlap test refuses far more than the engine +/// does, and a shadow that lies about a refusal reads as a broken timeline. +pub(crate) fn cross_room(at: u32, len: u32, others: &[(u32, u32)]) -> Option { + let (mut lo, mut hi) = (0, u32::MAX); + for &(other_start, other_end) in others { + if other_start <= at && at < other_end { + return None; + } + match other_end <= at { + true => lo = lo.max(other_end), + false => hi = hi.min(other_start), + } + } + match hi - lo < len { + true => None, + false => Some(at.clamp(lo, hi - len)), + } } /// Where a clip staying on its own lane really comes to rest: `want`, clamped @@ -929,17 +942,20 @@ mod drop_landing_tests { 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. + /// The cross-lane shadow's rule, mirroring the engine: refused only when + /// the asked head is inside a take or the gap is too narrow, and otherwise + /// clamped into the gap rather than refused. The middle case is the + /// verifier's repro -- an obstacle at (360, 420), a 90-frame clip asked at + /// 315, which the engine lands at 270. #[test] - fn a_landing_on_top_of_a_take_previews_as_refused() { - let others = [(100, 200), (400, 500)]; - assert!(collides(150, 50, &others), "inside the first take"); - assert!(collides(90, 50, &others), "its head laps the first take"); - assert!(collides(50, 400, &others), "long enough to swallow both"); - assert!(!collides(50, 50, &others), "tail meets the head exactly"); - assert!(!collides(200, 200, &others), "the gap holds it exactly"); - assert!(!collides(500, 10, &others), "past the last take"); + fn a_cross_lane_landing_clamps_into_the_gap_the_engine_leaves() { + let others = [(360, 420)]; + assert_eq!(cross_room(315, 90, &others), Some(270), "clamped, not refused"); + assert_eq!(cross_room(380, 90, &others), None, "head inside the take"); + assert_eq!(cross_room(100, 90, &others), Some(100), "room to spare"); + let tight = [(0, 100), (150, 300)]; + assert_eq!(cross_room(120, 90, &tight), None, "the gap is 50 frames wide"); + assert_eq!(cross_room(120, 50, &tight), Some(100), "and holds a 50-frame clip"); + assert_eq!(cross_room(500, 90, &[]), Some(500), "an empty lane takes it as asked"); } } diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs index 3e3601d..b46a65f 100644 --- a/crates/app/src/ui/bench_stance.rs +++ b/crates/app/src/ui/bench_stance.rs @@ -328,7 +328,19 @@ fn clip_box( }, { let ghost = ghost.clone(); - move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())) + let me = cx.entity(); + move |_, _, _, cx| { + // A fresh gesture inherits nothing: `Player::drag_lane` + // and `Player::drag_x` are the *last live sample* of the + // drag being made, and a drag whose first sample lands + // outside every row would otherwise be let go onto the + // lane the previous one ended over. + me.update(cx, |this, _| { + this.drag_lane = None; + this.drag_x = None; + }); + cx.new(|_| Tip(ghost.clone())) + } }, ) .tooltip(crate::ui::widgets::tip_hover("Clip", "drag to move", None)) @@ -717,7 +729,19 @@ fn sub_box( }, { let ghost = ghost.clone(); - move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())) + let me = cx.entity(); + move |_, _, _, cx| { + // A fresh gesture inherits nothing: `Player::drag_lane` + // and `Player::drag_x` are the *last live sample* of the + // drag being made, and a drag whose first sample lands + // outside every row would otherwise be let go onto the + // lane the previous one ended over. + me.update(cx, |this, _| { + this.drag_lane = None; + this.drag_x = None; + }); + cx.new(|_| Tip(ghost.clone())) + } }, ) .tooltip(crate::ui::widgets::tip_hover("Subtitle", "drag to move", None)) @@ -892,7 +916,7 @@ fn lane_row( // pointer actually being inside this *row's* bounds, since // `on_drag_move` fires on every painted element of the drag's // type, not just the one under the pointer. The row and not the - // bed: the head column is 72px of this lane too, and a clip + // bed: the head column is `HEAD_W` px of this lane too, and a clip // dragged out over it is aiming at frame 0 -- the drop it used to // fall through (nothing under the pointer answered `ClipDrag`) is // the "I have to be pixel perfect to snap to 0" complaint. @@ -905,6 +929,11 @@ fn lane_row( } let path = event.drag(cx).0.clone(); this.drag_x = Some(event.event.position.x); + // The row the catch-all release below aims at. A file's own + // kind is not known until the engine has placed it, so the + // last row hovered is the answer and `Player::insert_source` + // words the refusal if it cannot hold this file. + this.drag_lane = Some(lane); this.drag_alt = event.event.modifiers.alt; this.preview_ghost_asset(&path, lane, event.event.position.x, cx); }), @@ -956,6 +985,7 @@ fn lane_row( } let drag = *event.drag(cx); this.drag_x = Some(event.event.position.x); + this.drag_lane = held_lane(this.drag_lane, lane, drag.lane); this.drag_alt = event.event.modifiers.alt; this.preview_ghost_sub(&drag, lane, event.event.position.x, cx); }), @@ -976,6 +1006,7 @@ fn lane_row( } let track = event.drag(cx).0; this.drag_x = Some(event.event.position.x); + this.drag_lane = Some(lane); this.drag_alt = event.event.modifiers.alt; this.preview_ghost_pick(track, lane, event.event.position.x, cx); }), @@ -1096,7 +1127,7 @@ fn lane_row( // DESIGN §7: the lanes scroll BEHIND the pinned heads. A // clip whose start is left of the view sits at a negative // `left`, and without a clip mask gpui paints it -- and its - // hitbox -- straight over the 72px head column, so V1/A1 and + // hitbox -- straight over the `HEAD_W` px head column, so V1/A1 and // their verbs vanish under it. The mask cuts painting and // hit-testing at the bed's own edges together, so the visible // half of a half-scrolled clip still drags and trims and the @@ -1321,6 +1352,46 @@ pub(crate) fn render( this.drag_alt = window.modifiers().alt; this.move_clip(drag.lane, idx, lane, x, cx); })) + // The same catch-all for the other three things a hand can be holding + // over the bench -- a library row, a caption already down, a palette + // row. Each lands on the lane its last live sample was over, through + // the very door that row's own release uses, so the engine words the + // refusal when that lane cannot hold it. Without these, letting one go + // off the rows reached nothing at all. + .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { + let Some(lane) = this.drag_lane else { + return; + }; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.drag_alt = window.modifiers().alt; + let at = this.place_frame(x).0; + this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx); + })) + .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { + let Some(lane) = this.drag_lane else { + return; + }; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.drag_alt = window.modifiers().alt; + this.move_sub(drag, lane, x, cx); + })) + .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { + let Some(lane) = this.drag_lane else { + return; + }; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.drag_alt = window.modifiers().alt; + this.place_sub(drag.0, lane, x, cx); + })) .child( // Pinned ruler: click/drag to seek (reuses `Player::scrub_to`, // the same call the legacy ruler makes), tick marks with mono diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 161e43f..2c897fe 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -376,8 +376,20 @@ fn source_row( // drag media in timeline") was the dock showing the *legacy* // panel, which the darkroom bench was never wired against; // this row is the darkroom's own half of that pairing. - .on_drag(AssetDrag(dragged.0, dragged.1), move |_, _, _, cx| { - cx.new(|_| Tip(ghost.clone())) + .on_drag(AssetDrag(dragged.0, dragged.1), { + let me = cx.entity(); + move |_, _, _, cx| { + // A fresh gesture inherits nothing: `Player::drag_lane` + // and `Player::drag_x` are the *last live sample* of the + // drag being made, and a drag whose first sample lands + // outside every row would otherwise be let go onto the + // lane the previous one ended over. + me.update(cx, |this, _| { + this.drag_lane = None; + this.drag_x = None; + }); + cx.new(|_| Tip(ghost.clone())) + } }) }) .tooltip(crate::ui::widgets::tip_hover("Source", "drag to a lane", None)) @@ -675,8 +687,20 @@ fn subtitle_tab_rows( .when(usable, |d| { d.cursor_pointer() .hover(|s| s.bg(rgb(DARK_RAISED()))) - .on_drag(SubPick(track), move |_, _, _, cx| { - cx.new(|_| Tip(ghost.clone())) + .on_drag(SubPick(track), { + let me = cx.entity(); + move |_, _, _, cx| { + // A fresh gesture inherits nothing: `Player::drag_lane` + // and `Player::drag_x` are the *last live sample* of the + // drag being made, and a drag whose first sample lands + // outside every row would otherwise be let go onto the + // lane the previous one ended over. + me.update(cx, |this, _| { + this.drag_lane = None; + this.drag_x = None; + }); + cx.new(|_| Tip(ghost.clone())) + } }) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.sub_track = track;