diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 984370d..3298dfb 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -333,6 +333,14 @@ struct Player { /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement /// no magnet may take away. snap: bool, + /// Whether `alt` was down on the last sample of the gesture in flight: + /// snapping off for *this* drag only, the override every NLE has for the + /// one clip that has to sit a frame off an edge, leaving [`Player::snap`] + /// -- the switch -- exactly as the hand left it. Read by + /// [`Player::snap_live`], written by the bench's own drag samples and by + /// the trim's, and stale between gestures, which costs nothing: every + /// gesture writes it before it asks. + drag_alt: bool, /// Whether the subtitle lanes draw at all -- the mute over the shown lane /// ([`Player::sub_lane`]), not a lane of its own. On by default and off by /// one stroke @@ -398,6 +406,12 @@ struct Player { /// the pointer is not guaranteed to answer what the ghost just showed /// (DESIGN: "drop == shadow, by construction"). `None` between drags. drag_x: Option, + /// The lane the last live sample of the drag in flight was over -- the one + /// a release off the rows themselves (left of the heads, between two rows, + /// below the last track) lands on, so a gesture that has already promised a + /// landing in the shadow cannot end in nothing. `None` before the pointer + /// has been over any lane, where there is no landing to promise. + drag_lane: Option, /// The slot a track header being dragged is about to drop into, or `None` /// while the pointer is over no lane: the line drawn between two headers, /// for the reason [`Player::ghost`] draws a shadow -- where a gesture lands @@ -935,6 +949,7 @@ fn main() { fade_drag: None, grab: 0, snap: true, + drag_alt: false, subs_on: true, sub_track: 0, sub_folded: HashSet::new(), @@ -942,6 +957,7 @@ fn main() { snap_cue: None, ghost: Vec::new(), drag_x: None, + drag_lane: None, lane_drop: None, last_scrub: Instant::now(), last_target: 0, diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index f99b977..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(); } @@ -751,7 +758,7 @@ impl Player { self.frame_under(x), self.grab, sub.frames, - self.snap, + self.snap_live(), self.drop_snap_frames(), &marks, ) @@ -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. /// @@ -824,7 +831,7 @@ impl Player { self.frame_under(x), self.grab, clip.frames(), - self.snap, + self.snap_live(), self.drop_snap_frames(), &marks, )) @@ -841,7 +848,7 @@ impl Player { self.frame_under(x), 0, 0, - self.snap, + self.snap_live(), self.drop_snap_frames(), &marks, ) @@ -887,12 +894,49 @@ impl Player { self.set_ghost(Vec::new(), cx); return; }; + // What the release would refuse: a lane of the other kind, and a head + // let go on top of a take already there ([`Project::move_selection`] + // changes nothing rather than overwrite one). Drawn as refused so a + // drop that will not happen is seen before the hand lets go, never as a + // silent no-op. The neighbours are the destination lane's clips less + // whatever travels with this one -- itself and its link group. + let neighbours: Vec<(u32, u32)> = self + .session + .as_ref() + .map(|session| { + session + .lane_clips(to) + .iter() + .enumerate() + .filter(|&(i, clip)| { + (to, i) != (drag.lane, idx) + && !(clip.link.is_some() && clip.link == drag.clip.link) + }) + .map(|(_, clip)| (clip.start, clip.end())) + .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 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 => match cross_room(start, len, &neighbours) { + Some(landed) => (landed, false), + None => (start, true), + }, + }; 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, + refused: drag.lane.kind != to.kind || refused, }; let mut ghosts = vec![anchor]; if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 { @@ -1046,13 +1090,13 @@ impl Player { .flatten() }); let skip = skip.and_then(|(lane, idx)| Some((lanes.iter().position(|&l| l == lane)?, idx))); - snap_marks(&clips, skip, skip_link, frame_at(session.now(), self.fps)) - } - - /// Where a gesture at `raw` lands and the mark that pulled it there, with - /// the switch honoured: snapping off, nothing moves and no line is drawn. - pub(crate) fn snap_to(&self, raw: u32, len: u32, marks: &[u32]) -> (u32, Option) { - snap_cue(self.snap, raw, len, self.snap_frames(), marks) + snap_marks( + &clips, + skip, + skip_link, + frame_at(session.now(), self.fps), + self.range, + ) } /// Every timeline frame that is a *source* sync point: each clip's own @@ -1145,9 +1189,21 @@ 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 + /// Resolve, Premiere and Final Cut all put on the same key. The switch is + /// not touched, so the stroke that follows the drag finds it where it was. + /// Every landing on this timeline asks it, so the shadow, the line and the + /// drop can never disagree about whether a magnet was on. + pub(crate) fn snap_live(&self) -> bool { + 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) } @@ -1448,7 +1504,16 @@ impl Player { // The edge is pulled onto the same marks a whole clip is, by itself: // there is no other end travelling with it, so it snaps at length zero. let marks = self.snap_targets(Some((trim.lane, trim.idx))); - let (at, cue) = self.snap_to(self.frame_under(x), 0, &marks); + // The same 10 px of aim a drop is given ([`DROP_SNAP_PX`]): one + // threshold for every gesture on this bed, so an edge and a whole clip + // grip a cut at the same distance from it. + let (at, cue) = snap_cue( + self.snap_live(), + self.frame_under(x), + 0, + self.drop_snap_frames(), + &marks, + ); let Some((lo, hi)) = self.session.as_ref().and_then(|session| { match trim.lane.kind == LaneKind::Subtitle { // The walls a caption's edge has -- its neighbour, its own @@ -2005,7 +2070,10 @@ impl Player { // outside the window, still owing its one edit. if self.trim.is_some() { match event.pressed_button { - Some(MouseButton::Left) => self.trim_to(event.position.x, cx), + Some(MouseButton::Left) => { + self.drag_alt = event.modifiers.alt; + self.trim_to(event.position.x, cx); + } _ => self.commit_trim(cx), } return; @@ -2131,6 +2199,7 @@ impl Player { if self.trim.is_some() { // The release lands exactly, then the gesture is // written once -- one edit, one undo step. + self.drag_alt = event.modifiers.alt; self.trim_to(event.position.x, cx); self.commit_trim(cx); return; diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index 2e61258..977b6bb 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -1670,9 +1670,12 @@ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() { // bed: ten seconds in, five seconds past the end of the timeline, and // no mark anywhere near enough to pull it back. let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)]; - let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps)); + 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 70a5e82..075f1b4 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/tests/view.rs b/crates/app/src/tests/view.rs index d6face9..baa14b0 100644 --- a/crates/app/src/tests/view.rs +++ b/crates/app/src/tests/view.rs @@ -175,7 +175,7 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { let lanes: [&[Clip]; 2] = [&video, &audio]; // Nothing in the hand: both lanes' edges, the playhead, and 0. - let mut all = snap_marks(&lanes, None, None, 300); + let mut all = snap_marks(&lanes, None, None, 300, None); all.sort_unstable(); assert_eq!(all, [0, 100, 100, 160, 160, 300, 400, 430]); @@ -184,12 +184,12 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { // other lane -- both boxes travel with the drag. The lone audio clip is // still a target, which is the whole point: a take being carried on V1 // lands flush with a sound on A1. - let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300); + let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300, None); carried.sort_unstable(); assert_eq!(carried, [0, 300, 400, 430]); // An index that names no clip skips nothing and still answers. - assert_eq!(snap_marks(&[], Some((3, 9)), None, 0), [0, 0]); + assert_eq!(snap_marks(&[], Some((3, 9)), None, 0, None), [0, 0]); } /// The line the bed draws, and the switch that turns the whole thing off. diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index c566853..b258332 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -583,6 +583,7 @@ pub(crate) fn snap_marks( skip: Option<(usize, usize)>, skip_link: Option, playhead: u32, + range: Option<(u32, u32)>, ) -> Vec { let mut marks: Vec = lanes .iter() @@ -599,6 +600,13 @@ pub(crate) fn snap_marks( .collect(); marks.push(playhead); marks.push(0); + // The in and out points ([`Player::range`]): a hand that has marked a + // stretch is working to it, and a clip meets its brackets as readily as it + // meets a cut. + if let Some((in_, out)) = range { + marks.push(in_); + marks.push(out); + } marks } @@ -626,6 +634,15 @@ pub(crate) fn snap_cue( (start, mark) } +/// Whether the magnet is on for the gesture in flight: the switch, unless +/// `alt` is held -- the temporary override Resolve, Premiere and Final Cut all +/// put on that key, off for this one drag and leaving the switch where the hand +/// left it. [`Player::snap_live`]'s whole rule, here so it can be read without +/// a window. +pub(crate) fn snap_live(on: bool, alt: bool) -> bool { + on && !alt +} + /// Where a drag lands and the mark that pulled it there: the frame under the /// pointer, less however far into the box the hand grabbed it (so a clip travels /// with the pointer rather than jumping its head under it), snapped by @@ -644,6 +661,70 @@ pub(crate) fn landing( snap_cue(on, under.saturating_sub(grab), len, tol, marks) } +/// 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. +/// +/// 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 +/// 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 +/// to the empty bench below is still aiming at V1. [`Player::drag_lane`]'s +/// whole rule. +pub(crate) fn held_lane(prev: Option, over: Lane, from: Lane) -> Option { + match over.kind == from.kind { + true => Some(over), + false => prev, + } +} + /// Why this file may not go on that lane, in the words the refusal is told in -- /// `None` when it may. A file with no picture belongs on an audio lane and /// nowhere else, and a still is silent, so an audio lane is the one place it @@ -697,7 +778,7 @@ mod drop_landing_tests { /// missing mark. #[test] fn a_pull_near_the_head_of_an_empty_timeline_snaps_to_frame_0() { - let marks = snap_marks(&[&[]], None, None, 0); + let marks = snap_marks(&[&[]], None, None, 0, None); assert!(marks.contains(&0), "an empty timeline still offers frame 0"); assert_eq!(snapped(4, 0, 10, &marks), 0); // Outside the tolerance, the raw ask stands: this is a magnet, not a @@ -719,8 +800,162 @@ mod drop_landing_tests { /// where the timeline is parked. #[test] fn a_pull_near_the_playhead_snaps_onto_it() { - let marks = snap_marks(&[&[]], None, None, 500); + let marks = snap_marks(&[&[]], None, None, 500, None); assert!(marks.contains(&500)); assert_eq!(snapped(493, 0, 10, &marks), 500); } + + /// The user's own repro: a clip dragged left through the lane-head column + /// -- window x *left of the bed* -- lands on frame 0 rather than nowhere. + /// Two clamps do it, and both are on the path the bench now takes for a + /// drop over the head ([`Player::frame_under`]): [`px_along`] pins an x + /// before the bed's left edge to 0 px, [`Scale::time_at`] pins the moment + /// to 0 s, and the grab offset comes off with a saturating subtraction, so + /// even a clip held by its tail cannot ask for a negative frame. + #[test] + fn a_drag_out_over_the_lane_head_lands_on_frame_0() { + let bed = Bounds { + origin: point(px(100.), px(0.)), + size: size(px(900.), px(60.)), + }; + let scale = Scale::default(); + // 40 px into the head column, and off the window entirely. + for x in [px(60.), px(-400.)] { + assert_eq!(px_along(x, bed), 0.); + let under = frame_at(scale.time_at(px_along(x, bed)), 25.); + assert_eq!(under, 0); + // Grabbed 30 frames into the box: still frame 0, never a refusal. + assert_eq!(landing(under, 30, 50, true, 10, &[0, 300]), (0, Some(0))); + } + } + + /// Both edges of the clip in the hand are candidates and the nearest one + /// wins: a tail 2 frames short of a neighbour's head beats a head 8 frames + /// from the timeline's start. + #[test] + fn the_nearer_of_the_two_edges_wins() { + let marks = [0, 300, 500]; + // len 292: the tail wants 300 (2 away), the head 0 (8 away). + // The tail already sits exactly on 300, so the head is left alone. + assert_eq!(snapped(8, 292, 10, &marks), 8); + assert_eq!(snapped(6, 292, 10, &marks), 8, "tail meets 300, head stays"); + } + + /// The threshold is a distance on *screen*: the same 10 px of aim at two + /// zooms is a different number of frames, which is what makes the magnet + /// feel identical zoomed in and zoomed out ([`Scale::drop_snap_frames`]). + /// Outside it the drag follows the pointer exactly. + #[test] + fn the_threshold_is_ten_pixels_at_any_zoom() { + let fps = 25.; + for pps in [50., 400.] { + let scale = Scale { pps, start: 0. }; + let tol = scale.drop_snap_frames(fps); + // 10 px worth of frames, and one frame more than that is not near. + let near = (DROP_SNAP_PX / pps * fps) as u32; + assert_eq!(tol, near); + assert_eq!(snapped(500 + tol, 0, tol, &[500]), 500); + assert_eq!( + snapped(500 + tol + 1, 0, tol, &[500]), + 500 + tol + 1, + "past the window the pointer is obeyed exactly" + ); + } + } + + /// `alt` held turns the magnet off for the gesture and nothing else: the + /// same raw ask, no line, and [`Player::snap`] itself untouched. + #[test] + fn alt_turns_the_magnet_off_for_this_drag_only() { + let on = true; + assert!(snap_live(on, false)); + assert!(!snap_live(on, true)); + let marks = [0, 300]; + assert_eq!( + snap_cue(snap_live(on, true), 297, 0, 10, &marks), + (297, None) + ); + assert_eq!(snap_cue(snap_live(on, false), 297, 0, 10, &marks), (300, Some(300))); + // The switch off stays off however the modifier is held. + assert!(!snap_live(false, false)); + } + + /// Every target an NLE offers is on the list: frame 0, the playhead, both + /// edges of every clip on *every* lane, and the in/out brackets. + #[test] + fn the_targets_are_zero_the_playhead_the_edges_and_the_marks() { + let clip = |start: u32, frames: u32| Clip { + fade_in: 0, + fade_out: 0, + transition_out: 0, + start, + in_frame: 0, + out_frame: frames, + source: 0, + link: None, + eq: None, + color: None, + transform: None, + fit: Default::default(), + speed: Default::default(), + }; + let v1 = [clip(100, 50), clip(400, 50)]; + let a1 = [clip(700, 20)]; + let marks = snap_marks(&[&v1, &a1], None, None, 900, Some((250, 600))); + for want in [0, 900, 100, 150, 400, 450, 700, 720, 250, 600] { + assert!(marks.contains(&want), "{want} is not a snap target"); + } + // And each of them actually pulls a drag onto itself. + for target in [0, 250, 600, 900] { + assert_eq!(snapped(target + 4, 0, 10, &marks), target); + } + } + + /// A release on the empty bench below the last row, or left of the heads, + /// lands on the lane the last live sample was over -- and a lane of the + /// wrong kind crossed on the way down never steals it. + #[test] + fn the_last_lane_that_could_hold_it_keeps_the_drag() { + let v1 = Lane::V1; + let v2 = Lane::new(LaneKind::Video, 1); + let a1 = Lane::A1; + // The head column is part of the row, so the row over it is the answer. + assert_eq!(held_lane(None, v1, v1), Some(v1)); + assert_eq!(held_lane(Some(v1), v2, v1), Some(v2)); + assert_eq!(held_lane(Some(v2), a1, v1), Some(v2), "audio cannot hold it"); + // Nothing promised yet and nothing that can hold it: no landing. + 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 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_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 dd5a256..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)) @@ -877,6 +901,116 @@ fn lane_row( this.preview_lane_drop(event.drag(cx).0, lane, cx); }), ) + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { + this.drag_alt = window.modifiers().alt; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + let at = this.place_frame(x).0; + this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) + })) + // The landing shadow (`Player::preview_ghost_asset`, the same + // setter `ui/timeline.rs`'s own bed calls) -- guarded on the + // 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 `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. + // `Player::frame_under` clamps an x left of the bed to the head of + // the view (`px_along`), so the head column reads as frame 0. + .on_drag_move( + cx.listener(move |this, event: &DragMoveEvent, _, cx| { + if !event.bounds.contains(&event.event.position) { + return; + } + 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); + }), + ) + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { + this.drag_alt = window.modifiers().alt; + let Some(idx) = this.dragged(drag) else { + return; + }; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.move_clip(drag.lane, idx, lane, x, cx) + })) + .on_drag_move( + cx.listener(move |this, event: &DragMoveEvent, _, cx| { + if !event.bounds.contains(&event.event.position) { + return; + } + let drag = *event.drag(cx); + this.drag_x = Some(event.event.position.x); + // The last lane this clip could actually land on: a picture + // clip dragged down across A1 on its way to the empty bench + // below is still aiming at V1, and the catch-all release must + // not hand it the audio lane that refused it on the way past. + this.drag_lane = held_lane(this.drag_lane, lane, drag.lane); + this.drag_alt = event.event.modifiers.alt; + this.preview_ghost(&drag, lane, event.event.position.x, cx); + }), + ) + // A caption already on a lane moves along it, or onto another + // subtitle track, exactly as a clip does (`Player::move_sub`, + // the same call `ui/timeline.rs`'s own bed makes). + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { + this.drag_alt = window.modifiers().alt; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.move_sub(drag, lane, x, cx); + })) + .on_drag_move( + cx.listener(move |this, event: &DragMoveEvent, _, cx| { + if !event.bounds.contains(&event.event.position) { + return; + } + 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); + }), + ) + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { + this.drag_alt = window.modifiers().alt; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.place_sub(drag.0, lane, x, cx); + })) + .on_drag_move( + cx.listener(move |this, event: &DragMoveEvent, _, cx| { + if !event.bounds.contains(&event.event.position) { + return; + } + 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); + }), + ) .child( // Pinned track head: its drag handle remains the lane label; verbs // stay separate pointer targets so a mix/remove click never starts @@ -993,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 @@ -1019,15 +1153,6 @@ fn lane_row( .h_full() .bg(rgba(DARK_SEAM())), ) - .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) - .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { - let x = this - .drag_x - .take() - .unwrap_or_else(|| window.mouse_position().x); - let at = this.place_frame(x).0; - this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) - })) // Right-click on empty bed space: the "Close Gap" door. A // clip's own right-click handler (`clip_box`/`sub_box`) never // stops propagation, so this fires on that press too -- @@ -1060,81 +1185,6 @@ fn lane_row( } }), ) - // The landing shadow (`Player::preview_ghost_asset`, the same - // setter `ui/timeline.rs`'s own bed calls) -- guarded on the - // pointer actually being inside this bed's own bounds, since - // `on_drag_move` fires on every painted element of the drag's - // type, not just the one under the pointer. - .on_drag_move( - cx.listener(move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let path = event.drag(cx).0.clone(); - this.drag_x = Some(event.event.position.x); - this.preview_ghost_asset(&path, lane, event.event.position.x, cx); - }), - ) - .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) - .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { - let Some(idx) = this.dragged(drag) else { - return; - }; - let x = this - .drag_x - .take() - .unwrap_or_else(|| window.mouse_position().x); - this.move_clip(drag.lane, idx, lane, x, cx) - })) - .on_drag_move( - cx.listener(move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let drag = *event.drag(cx); - this.drag_x = Some(event.event.position.x); - this.preview_ghost(&drag, lane, event.event.position.x, cx); - }), - ) - // A caption already on a lane moves along it, or onto another - // subtitle track, exactly as a clip does (`Player::move_sub`, - // the same call `ui/timeline.rs`'s own bed makes). - .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) - .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { - let x = this - .drag_x - .take() - .unwrap_or_else(|| window.mouse_position().x); - this.move_sub(drag, lane, x, cx); - })) - .on_drag_move( - cx.listener(move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let drag = *event.drag(cx); - this.drag_x = Some(event.event.position.x); - this.preview_ghost_sub(&drag, lane, event.event.position.x, cx); - }), - ) - .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) - .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { - let x = this - .drag_x - .take() - .unwrap_or_else(|| window.mouse_position().x); - this.place_sub(drag.0, lane, x, cx); - })) - .on_drag_move( - cx.listener(move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let track = event.drag(cx).0; - this.drag_x = Some(event.event.position.x); - this.preview_ghost_pick(track, lane, event.event.position.x, cx); - }), - ) .tooltip(crate::ui::widgets::tip_hover("Lane bed", "drop media here", None)) .children(hitmap::dynamic( move || { @@ -1210,6 +1260,9 @@ fn lane_row( /// The bench's content: pinned ruler, pinned heads, lane stack -- compressed /// evenly to [`LANES_COMPRESS`] rows and then scrolling (DESIGN §7). +/// The bench's side gutter, spent inside [`render`]'s own content box. +const BENCH_GUTTER: f32 = 12.; + pub(crate) fn render( player: &mut Player, box_h: f32, @@ -1273,6 +1326,72 @@ pub(crate) fn render( .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { this.timeline_wheel(event, cx); })) + // The bench's side gutter, spent here rather than by the `bench` div + // above, so this element's bounds -- and the catch-all release below + // with them -- reach the window edge (note at `ui::stance::bench`). + .px(px(BENCH_GUTTER)) + // The catch-all release: a clip let go of anywhere on the bench that is + // not a lane row -- left of the tracks, in the gap between two rows, on + // the empty bench below the last one -- lands on the lane and the x the + // last live sample of that same drag was over (`Player::drag_lane`, + // `Player::drag_x`), which is exactly what the shadow was drawn at. A + // release that reaches no drop target at all is the one thing a drag + // may never do: a hand that has aimed a clip and let go has made an + // edit, and "nothing happened" is not one of the answers an editor + // accepts. A row's own listener stops propagation when it answers, so + // this only ever runs when none did -- and it would answer with the + // same frame if it did run, since both read the one sample. + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { + let (Some(lane), Some(idx)) = (this.drag_lane, this.dragged(drag)) else { + return; + }; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + 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; diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index c1ebaea..47fb732 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -615,7 +615,14 @@ fn bench( // the bench is the selection one a picked clip draws (DESIGN §2/§4). .flex() .flex_col() - .px(px(12.)) + // The 12px side gutter is spent INSIDE `bench_stance`'s own content + // box, not here: gpui fires `on_drop` only on an element whose own + // hitbox holds the pointer (`div.rs:2089`), and padding on this + // parent left the gutter outside every registered target -- a clip + // let go at x < 12, hard against the left edge where a hand aiming + // at frame 0 puts it, reached nothing at all and moved nothing, + // silently (DESIGN §8: a release that has aimed has made an edit). + // Same box, same pixels; only the catch-all's bounds grow. .py(px(4.)) .child(bench_stance::render(player, bench_h - BENCH_CHROME_H, cx)) }