diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs index ab4fe71..fa9ae08 100644 --- a/crates/app/src/menus.rs +++ b/crates/app/src/menus.rs @@ -2,14 +2,28 @@ use crate::*; -/// An open clip menu: which clip it was opened on, where it hangs, and whether -/// it has been turned over to show what that clip *is* instead of what can be -/// done to it. The lane and index are the ones the same click selected, so -/// every item acts on exactly the box under the pointer. +/// What a right-click on the bench named: a clip at an index, or the empty +/// stretch of the lane it landed in ([`engine::PlaybackSession::gap_at`]) -- +/// two different things the one menu can be about, so it stays one struct and +/// one field to clear rather than a second `Option` beside `context_menu` +/// that every closer would have to learn about too. +#[derive(Clone, Copy)] +pub(crate) enum MenuOn { + Clip(usize), + /// `(start, frames)` of the gap, in timeline frames -- what + /// [`Player::close_gap`] ripples shut. + Gap(u32, u32), +} + +/// An open clip menu: what it was opened on, where it hangs, and whether it +/// has been turned over to show what a clip *is* instead of what can be done +/// to it (`details` means nothing for a gap, which has no properties side). +/// The lane is the one the same click selected, so every item acts on +/// exactly the box -- or the hole -- under the pointer. #[derive(Clone, Copy)] pub(crate) struct ContextMenu { pub(crate) lane: Lane, - pub(crate) idx: usize, + pub(crate) on: MenuOn, pub(crate) at: Point, pub(crate) details: bool, } diff --git a/crates/app/src/notices.rs b/crates/app/src/notices.rs index 7a854c0..7368200 100644 --- a/crates/app/src/notices.rs +++ b/crates/app/src/notices.rs @@ -58,3 +58,38 @@ pub(crate) fn audio_notice(session: &PlaybackSession) -> Option { .audio_disabled_reason() .map(|reason| format!(" — NO AUDIO: {reason}")) } + +#[cfg(test)] +mod tests { + use super::*; + + /// The class this guards: a notice queued behind an earlier, undismissed + /// one is never *lost* -- `push_notice` still appends it to the back -- + /// but a reader of `front()` alone (what `stance::notice_plate` read + /// before this fix) would never see it, because nothing but a keystroke + /// ever calls `dismiss_notice`, and most of what fills this queue (a + /// click on a gap, a menu row, a drag) is not one. `back()` is the read + /// that survives that: it always names the newest message, which is why + /// the plate and the ledger's "last action" both read it now. + /// + /// This is a value-level check on the queue only -- this binary has no + /// `TestAppContext`, so it cannot measure what actually painted, and this + /// test does not claim to. + #[test] + fn a_notice_queued_behind_an_unread_one_is_still_reachable_at_the_back() { + let mut notices = std::collections::VecDeque::new(); + push_notice(&mut notices, "SAVED test_h264.edith".into()); + let refusal = "the V1 clip at frame 0 is one take with the A1 clip at frame 0: \ + closing this gap alone would pull the take out of sync — close A1's \ + gap there too, or detach them first"; + push_notice(&mut notices, refusal.into()); + // Nobody dismissed the SAVED notice (no keystroke happened) -- it is + // still sitting at the front, exactly the scenario that froze the + // plate on stale text. + assert_eq!(notices.front().unwrap().as_ref(), "SAVED test_h264.edith"); + // The refusal, remedy clause and all, is reachable at the back -- + // whole, not truncated, because `push_notice` never touches a + // message's text. + assert_eq!(notices.back().unwrap().as_ref(), refusal); + } +} diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 6a8f8f8..d24950d 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1031,13 +1031,75 @@ impl Player { } self.context_menu = Some(ContextMenu { lane, - idx, + on: MenuOn::Clip(idx), + at, + details: false, + }); + cx.notify(); + } + + /// Opens the same menu on the gap under the pointer instead of a clip -- + /// the empty-bench-space door to [`Player::close_gap`]. Nothing is + /// selected: a gap owns no clip to select, unlike [`Player::open_menu`]. + pub(crate) fn open_gap_menu(&mut self, lane: Lane, start: u32, frames: u32, at: Point, cx: &mut Context) { + if self.modal() { + return; + } + self.context_menu = Some(ContextMenu { + lane, + on: MenuOn::Gap(start, frames), at, details: false, }); cx.notify(); } + /// Closes the gap `(start, frames)` -- Premiere's "Close Gap", scoped to + /// `lane` and, when the gap borders a take, to the take's other lane too + /// ([`engine::PlaybackSession::gap_take_scope`]): a lane not sharing the + /// take never moves, so a neighbour that meant to keep its own silence is + /// untouched, but the two halves of a linked A/V take close together -- + /// the alternative is a ripple that pulls a take's picture and sound out + /// of step with each other, which no lane's own gap is worth. A take + /// whose gap does not match on its other lane is refused in words, not + /// silence ([`engine::Project::gap_take_scope`]). + pub(crate) fn close_gap(&mut self, lane: Lane, start: u32, frames: u32, cx: &mut Context) { + let Some(session) = self.session.as_mut() else { + return; + }; + let scope = match session.gap_take_scope(lane, start, frames) { + Ok(scope) => scope, + Err(e) => { + self.notify_user(e.to_string().into()); + cx.notify(); + return; + } + }; + match session.cut_regions(&[(start, frames)], &scope) { + Ok(()) => { + self.mark_dirty(); + // The ripple moves every index after the gap on the scoped + // lanes, the same reason a delete drops the selection. + self.selected.clear(); + self.reset_after_reseek(); + let where_ = if scope.len() > 1 { + "its take".to_string() + } else { + lane.label().to_string() + }; + self.notify_user( + format!( + "GAP CLOSED on {where_} — {} takes it back", + self.keymap.display(ActionId::Undo) + ) + .into(), + ); + } + Err(e) => self.notify_user(e.to_string().into()), + } + cx.notify(); + } + /// A press on an edge: the start of the drag that changes how much of a /// source it plays. It picks the placement as a press anywhere else on the /// box does -- the edge strip covers the box's own listener (`occlude`), so diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index f168fa2..85e2e3d 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1930,6 +1930,31 @@ fn the_notice_plate_cannot_reach_the_bench_at_any_height() { ); } } +/// The renderer only wraps text when the text measurement receives a definite +/// width and normal whitespace. This source-level guard keeps both declarations +/// on the notice plate: `max_w` alone limits max-content after that measurement +/// and silently permits one-line overflow. It cannot inspect GPUI's painted +/// lines; only live driving can confirm the full notice actually wrapped. +#[test] +fn the_notice_plate_declares_a_bounded_wrapping_text_layout() { + let stance = src_text("ui/stance.rs"); + let notice_start = stance.find("fn notice_plate(").expect("notice plate moved or renamed"); + let notice_end = stance[notice_start..] + .find("\n/// Thin strip") + .map(|end| notice_start + end) + .expect("notice plate no longer precedes the ledger"); + let plate = &stance[notice_start..notice_end]; + + assert!( + plate.contains(".w_full()") && plate.contains(".max_w(px(480.))"), + "notice plate lacks a definite width bounded to 480 px; max_w alone does not wrap text" + ); + assert!( + plate.contains(".whitespace_normal()"), + "notice plate no longer explicitly requests GPUI's wrapping whitespace mode" + ); +} + /// A round trip through the file: what is saved is what the next load reads /// back, one seam touched and the other left at its default -- a scratch diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs index fa951f1..67df429 100644 --- a/crates/app/src/ui/bench_stance.rs +++ b/crates/app/src/ui/bench_stance.rs @@ -658,6 +658,24 @@ fn lane_row( let at = this.place_frame(window.mouse_position().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 -- + // harmlessly, since `gap_at` answers `None` for a frame a + // clip already covers and this listener does nothing then, + // leaving the clip's own menu exactly as it set it. + .on_mouse_down( + MouseButton::Right, + cx.listener(move |this, event: &MouseDownEvent, _, cx| { + let Some(session) = this.session.as_ref() else { + return; + }; + let frame = this.frame_under(event.position.x); + if let Some((start, frames)) = session.gap_at(lane, frame) { + this.open_gap_menu(lane, start, frames, event.position, 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 bed's own bounds, since diff --git a/crates/app/src/ui/overlays.rs b/crates/app/src/ui/overlays.rs index 1205d89..66c2db4 100644 --- a/crates/app/src/ui/overlays.rs +++ b/crates/app/src/ui/overlays.rs @@ -477,7 +477,11 @@ impl Player { // oracle's either way ([`Ctx::caption`]), so what the card *has* is // asked for where it is used rather than at the door -- refusing here // would be a right-click that opens nothing. - let clip = session.lane_clips(menu.lane).get(menu.idx).copied(); + let idx = match menu.on { + MenuOn::Clip(idx) => Some(idx), + MenuOn::Gap(..) => None, + }; + let clip = idx.and_then(|idx| session.lane_clips(menu.lane).get(idx).copied()); let source = clip.and_then(|clip| session.sources().get(clip.source).cloned()); let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps); // DESIGN §9/§3: a menu row is a plate row, Archivo at the room's @@ -562,6 +566,22 @@ impl Player { .into_any_element(), ); } + } else if let MenuOn::Gap(start, frames) = menu.on { + // The one item a gap offers: no properties, no clip actions, just + // the ripple that closes it -- Premiere's Close Gap, Resolve's + // Delete Gap, per-lane the way `Player::close_gap` documents. + rows.push( + row(rows.len()) + .cursor_pointer() + .hover(|s| s.bg(rgb(BG_HOVER()))) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.context_menu = None; + this.close_gap(menu.lane, start, frames, cx); + })) + .child("Close gap") + .child(chord_style(div().text_color(rgb(FG_SECONDARY()))).child("ripples left")) + .into_any_element(), + ); } else { // A grade on a waveform, an equalizer on a picture, a silence scan // on a still: things that do not exist for what was right-clicked, @@ -570,7 +590,8 @@ impl Player { // `menu_items`, so there is no second answer to keep in step. The // state refusals below stay, dimmed and saying why -- the next // click of the playhead lights them. - let ctx = self.ctx(Some((menu.lane, menu.idx))); + let idx = idx.expect("MenuOn::Gap handled above"); + let ctx = self.ctx(Some((menu.lane, idx))); for action in menu_items(ctx) { // The registry's own answer, the same one the actions card // dims a row with -- and a row that takes no click says *why* @@ -627,7 +648,7 @@ impl Player { // The stroke still steps -- same door. if action == ActionId::Fit { this.open_picker( - Pick::Fit(menu.lane, menu.idx), + Pick::Fit(menu.lane, idx), event.position(), cx, ); diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 5a58d5c..4d9ed30 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -562,9 +562,18 @@ pub(crate) fn notice_bottom_offset(bench_h: f32) -> f32 { /// A notice plate (DESIGN §8): one at a time, rising above the *bench*, its /// severity a 3px left spine rather than a colour flood. Fed by the same /// [`Player::notify_user`]/`notices` queue the legacy bar reads -/// ([`Player::notice_bar`]) -- no second notice channel. Dismissal is -/// already wired: [`render`]'s `on_key_down` calls `dismiss_notice()` on -/// every stroke, the same door the legacy handler uses. +/// ([`Player::notice_bar`]) -- no second notice channel. +/// +/// Reads the *back* of the queue, not the front: dismissal only ever fires +/// on a keystroke ([`render`]'s `on_key_down` calling `dismiss_notice()`), +/// and most of what fills this queue -- a click on a gap, a menu row, a +/// drag -- is not one. A `front()` plate left showing a `ctrl+s` "SAVED" +/// notice sat frozen through an unrelated mouse-driven refusal that queued +/// in behind it: the ledger strip's own "last action" already reads +/// `back()` for exactly this reason, and the plate disagreeing with it is +/// what made the refusal look like it never reached the notice surface at +/// all. `back()` keeps the two in step and guarantees the newest, most +/// actionable message is always the one on screen. /// /// Anchored off `bench_h` rather than a fixed offset off the ledger: at the /// bench's floor a fixed `LEDGER_H + 6.` bottom offset put the plate right @@ -585,9 +594,19 @@ fn notice_plate(message: SharedString, bench_h: f32) -> impl IntoElement { .absolute() .bottom(px(notice_bottom_offset(bench_h))) .left(px(12.)) - .max_w(px(360.)) - .flex() - .items_center() + // `max_w` only caps a box after GPUI has measured its text at + // max-content width. `w_full` supplies a definite width to that + // measurement (then `max_w` bounds it at 480 px), and normal + // whitespace gives the text system permission to shape every word + // into the resulting lines. Keep this a block: as a flex child the + // text's automatic min-content width can overflow its own plate. + // + // No fixed height: GPUI's shaped lines contribute their actual + // default `phi()` line boxes, so two or three lines grow upward from + // this bottom anchor without reaching down over the bench lanes. + .w_full() + .max_w(px(480.)) + .whitespace_normal() .px(px(10.)) .py(px(6.)) .rounded(px(2.)) @@ -922,7 +941,7 @@ pub(crate) fn render( .child(divider(Split::Bench, cx)) .child(bench(player, bench_h, cx)) .child(ledger(player, position)) - .when_some(player.notices.front().cloned(), |el, n| { + .when_some(player.notices.back().cloned(), |el, n| { el.child(notice_plate(n, bench_h)) }) .when(player.keys_open, |el| el.child(keys_overlay(player))) diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 5822f1a..e7d2448 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -2028,6 +2028,13 @@ impl PlaybackSession { self.project.lane(lane) } + /// The empty stretch of `lane` covering `frame`, or `None` when `frame` + /// is inside a clip or past the last one ([`Project::gap_at`]). What a + /// right-click on empty bench space asks before offering to close it. + pub fn gap_at(&self, lane: Lane, frame: u32) -> Option<(u32, u32)> { + self.project.gap_at(lane, frame) + } + /// Every lane's handle, in display order -- what a front-end lays out top to /// bottom, and the list [`add_lane`](Self::add_lane) grows. pub fn lanes(&self) -> Vec { @@ -2443,6 +2450,14 @@ impl PlaybackSession { .and_then(|s| s.from) } + /// The lanes closing the gap `(start, frames)` on `lane` must ripple + /// together to keep every take crossing it in sync + /// ([`Project::gap_take_scope`]) -- what a right-click on empty bench + /// space asks before offering to close it. + pub fn gap_take_scope(&self, lane: Lane, start: u32, frames: u32) -> crate::Result> { + self.project.gap_take_scope(lane, start, frames) + } + /// Cuts every one of `regions` -- `(start, len)` in timeline frames -- out /// of the lanes in `scope` and closes each hole, as **one** edit /// ([`Project::cut_regions`]): the jumpcut a silence scan diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 1b57300..07e7301 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -4180,6 +4180,83 @@ impl Project { true } + /// The empty stretch of `lane` covering `frame`, as `(start, len)` -- what + /// a right-click on empty bench space names before offering to close it. + /// `None` when `frame` sits inside a clip, or past the last one: the open + /// end of a lane is not a gap, since there is nothing after it to slide + /// back ([`gap`]). + pub fn gap_at(&self, lane: Lane, frame: u32) -> Option<(u32, u32)> { + gap(self.lane(lane), frame) + } + + /// The lanes closing the gap `(start, frames)` on `lane` must ripple + /// together to keep sync -- what a right-click on empty bench space asks + /// before the menu offers to close it, and what widens + /// [`cut_regions`](Project::cut_regions)'s scope from the one lane a hand + /// named to the whole take the gap might be half of. + /// + /// A clip bordering the gap on `lane` -- the one ending where it starts, + /// the one starting where it ends -- carries a link when it is one take + /// with a clip on another lane. That lane joins the scope only when the + /// *exact same* stretch is empty there too (same start, same length): the + /// ripple then removes nothing but silence, on every lane it touches, and + /// both halves stay the length they always were. A link whose partner + /// lane is not empty there -- a gap of a different length, or none at all + /// -- is named back to the caller rather than silently widened past + /// (which would cut real media out of a lane nothing asked to touch) or + /// silently left out (which is the defect this closes: a per-lane ripple + /// would leave [`scope_holds_takes_whole`](Project::scope_holds_takes_whole) + /// to refuse it after the fact, on the very half this could have carried + /// along). + /// + /// `Ok(vec![lane])` alone for a gap that borders no take, or none whose + /// partner clip sits on another lane -- the unlinked case, untouched. + pub fn gap_take_scope(&self, lane: Lane, start: u32, frames: u32) -> crate::Result> { + let Some(li) = self.index(lane) else { + return Err("no track to work on".into()); + }; + let labels = handles(&self.lanes); + let end = start + frames; + let mut scope = vec![lane]; + for c in self.lanes[li] + .clips + .iter() + .filter(|c| c.end() == start || c.start == end) + { + let Some(id) = c.link else { continue }; + for (j, data) in self.lanes.iter().enumerate() { + if j == li { + continue; + } + let Some(half) = data.clips.iter().find(|o| o.link == Some(id)) else { + continue; + }; + match gap(&data.clips, start) { + Some((s, f)) if s == start && f == frames => { + let other = labels[j]; + if !scope.contains(&other) { + scope.push(other); + } + } + _ => { + return Err(format!( + "the {} clip at frame {} is one take with the {} clip at frame {}: \ + closing this gap alone would pull the take out of sync -- close {}'s \ + gap there too, or detach them first", + labels[li].label(), + c.start, + labels[j].label(), + half.start, + labels[j].label() + ) + .into()); + } + } + } + } + Ok(scope) + } + /// Cut **every** one of `regions` -- `(start, len)` in timeline frames -- /// out of the lanes in `scope` and close each hole, as one edit: the /// jumpcut a silence scan asks for ([`crate::silence`]). @@ -4899,6 +4976,21 @@ fn at(clips: &[Clip], frame: u32) -> Option { (frame < clips[idx].end()).then_some(idx) } +/// The empty stretch of `clips` covering `frame`, as `(start, len)` -- `None` +/// when `frame` is inside a clip, or past the last one. Sorted-disjoint +/// invariant like [`at`]: the first clip whose start is past `frame` is the +/// far wall, and the last one that ends at or before `frame` (or the +/// timeline's own head, `0`, when there is none) is the near one. +fn gap(clips: &[Clip], frame: u32) -> Option<(u32, u32)> { + if at(clips, frame).is_some() { + return None; + } + let idx = clips.partition_point(|c| c.start <= frame); + let next = clips.get(idx)?; + let start = idx.checked_sub(1).map_or(0, |i| clips[i].end()); + Some((start, next.start - start)) +} + /// Index of the clip `frame` falls *strictly inside*, i.e. the one a split /// there would cut in two. A placement's own first frame is not inside it. fn splittable(clips: &[Clip], frame: u32) -> Option { @@ -7521,6 +7613,166 @@ mod tests { ); } + /// The gap-close menu's hit test: what `gap_at` says about a frame at the + /// head of a lane, between two clips, inside a clip, past the last one, + /// and on a lane holding nothing at all. + #[test] + fn gap_at_finds_the_hole_a_frame_sits_in() { + let mut p = Project::single(FILE, 1); + let v = p.add_lane(LaneKind::Video); + // Empty lane: nothing before and nothing after -- not a gap, since + // there is nothing to ripple toward. + assert_eq!(p.gap_at(v, 0), None, "an empty lane has nothing to close"); + + assert!(p.place(v, 5, clip(5, 0, 3, 0)), "single clip at [5,8)"); + // Before the only clip: the gap runs from the timeline's own head. + assert_eq!(p.gap_at(v, 0), Some((0, 5))); + assert_eq!(p.gap_at(v, 4), Some((0, 5))); + // Inside the clip: not a gap. + assert_eq!(p.gap_at(v, 5), None); + assert_eq!(p.gap_at(v, 7), None); + // Past the only clip: the open end of the lane, not a gap -- there is + // nothing after it to slide back. + assert_eq!(p.gap_at(v, 8), None); + assert_eq!(p.gap_at(v, 100), None); + + assert!(p.place(v, 12, clip(12, 0, 2, 0)), "a second clip at [12,14)"); + // Between the two: the gap [8,12). + assert_eq!(p.gap_at(v, 8), Some((8, 4))); + assert_eq!(p.gap_at(v, 11), Some((8, 4))); + assert_eq!(p.gap_at(v, 14), None, "still the open end"); + + assert!( + p.place(v, 8, clip(8, 0, 4, 0)), + "fills [8,12) exactly, meeting both neighbours" + ); + assert_eq!(p.gap_at(v, 8), None, "adjacent clips leave no frame to name a gap"); + assert_eq!(p.gap_at(v, 11), None); + } + + /// Closing a gap is [`Project::cut_regions`] scoped to the one lane the + /// menu named: the clip after the gap slides back on that lane, a clip on + /// another lane at the very same frame range does not move, and the whole + /// close is one press of undo. + #[test] + fn closing_a_gap_ripples_only_its_own_lane_and_undoes_in_one_step() { + let mut p = Project::single(FILE, 1); + let v = p.add_lane(LaneKind::Video); + let a = p.add_lane(LaneKind::Audio); + assert!(p.place(v, 5, clip(5, 0, 3, 0)), "V clip at [5,8)"); + assert!( + p.place(a, 0, clip(0, 0, 3, 0)), + "A clip at [0,3) -- outside the video lane's gap and this scope" + ); + let before = shape(&p); + let (start, len) = p.gap_at(v, 0).expect("a gap before the only clip"); + assert_eq!((start, len), (0, 5)); + assert!(p.cut_regions(&[(start, len)], &[v]).is_ok()); + assert_eq!(p.lane(v)[0].start, 0, "the clip slid back to close the gap"); + assert_eq!(p.lane(a)[0].start, 0, "the untouched lane's clip did not move"); + assert!(p.undo(), "one press undoes the whole close"); + assert_eq!(shape(&p), before, "back to exactly where it was"); + } + + /// A clip carrying an explicit link id -- what a + /// [`from_parts`](Project::from_parts) fixture below needs to build a take + /// by hand, the same shape `a_link_id_is_never_two_clips_of_one_lane` + /// already builds inline. + fn linked(start: u32, in_frame: u32, out_frame: u32, link: u32) -> Clip { + Clip { + fade_in: 0, + fade_out: 0, + transition_out: 0, + start, + in_frame, + out_frame, + source: 0, + link: Some(link), + eq: None, + color: None, + transform: None, + fit: FitPolicy::default(), + speed: Speed::NORMAL, + } + } + + /// The ordinary case the defect made a permanent no-op: a gap on `V1` + /// bordered by a linked take whose `A1` half is empty across the very + /// same stretch widens the scope to both lanes, so the ripple carries the + /// take rather than tearing it -- and one undo puts both halves back. + #[test] + fn closing_a_gap_carries_a_linked_take_when_the_gap_matches_on_both_lanes() { + let sources = vec![Source::new(FILE, 0)]; + let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; + let audio = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; + let mut p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) + .expect("valid parts"); + let before = shape(&p); + assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2))); + assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 2)), "the same stretch is empty on A1 too"); + + let scope = p + .gap_take_scope(Lane::V1, 3, 2) + .expect("a matching gap on both halves widens the scope"); + assert_eq!(scope.len(), 2, "the take's other lane joins"); + assert!(scope.contains(&Lane::V1) && scope.contains(&Lane::A1)); + + assert!(p.cut_regions(&[(3, 2)], &scope).is_ok()); + assert_eq!(p.lane(Lane::V1)[1].start, 3, "V1's far half slid back"); + assert_eq!(p.lane(Lane::A1)[1].start, 3, "A1's far half rode along, in sync"); + assert!(p.undo(), "one press undoes the whole close"); + assert_eq!(shape(&p), before, "back to exactly where it was"); + } + + /// The real design question: a take whose gap is not the *same size* on + /// both lanes cannot ripple by one number without pulling a lane's clip + /// out from under the other's sync -- refused by name, with the frame + /// naming which lane is out of step, rather than silently taking real + /// media off the shorter side. + #[test] + fn closing_a_gap_refuses_a_take_whose_gap_lengths_differ() { + let sources = vec![Source::new(FILE, 0)]; + let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; + // A1's second half starts at 4, not 5: its gap is [3,4), one frame + // shorter than V1's [3,5) -- a legal offset-preserving group, and + // still one take. + let audio = vec![linked(0, 0, 3, 1), linked(4, 5, 9, 3)]; + let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) + .expect("valid parts"); + assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2))); + assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 1)), "a shorter gap on A1"); + + let err = p + .gap_take_scope(Lane::V1, 3, 2) + .expect_err("a mismatched gap cannot ripple by one number") + .to_string(); + assert!(err.contains("A1"), "{err}"); + assert!(err.contains("out of sync"), "{err}"); + } + + /// A gap on `V1` whose `A1` half is not a gap at all -- real audio plays + /// there -- cannot close without cutting that audio out from under + /// nothing asked to touch it: refused, not widened silently past. + #[test] + fn closing_a_gap_refuses_a_take_whose_other_half_is_solid() { + let sources = vec![Source::new(FILE, 0)]; + let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; + // A1 plays through the whole span as one continuous clip, sharing + // V1's first-half link: nothing empty at frame 3 there at all. + let audio = vec![linked(0, 0, 9, 1)]; + let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) + .expect("valid parts"); + assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2))); + assert_eq!(p.gap_at(Lane::A1, 3), None, "A1 plays through, no gap there"); + + let err = p + .gap_take_scope(Lane::V1, 3, 2) + .expect_err("a solid partner cannot ripple with the gap") + .to_string(); + assert!(err.contains("A1"), "{err}"); + assert!(err.contains("detach"), "{err}"); + } + #[test] fn ripple_delete_spans_partial_clips() { let mut p = three();