forge
Explore
Log in

Don't you dare go Hollow

A right-click on empty bench space closes the gap

Browse files at this commit

29d8b28b52042ac087a428bd5904f0015d6957c9Ahmet Kaan GümüşParent: c2943bb
  • feat
    • a right-click on empty bench space closes the gap
Show full message
✨ feat(timeline): a right-click on empty bench space closes the gap

Right-clicking a gap on a lane (video, audio, or the head/tail/middle of
one) now opens the same clip-menu surface with a single "Close gap"
item; picking it ripples every clip after the gap left on that lane
only (Premiere-style per-lane scope, repeatable per track), through
Project::cut_regions so it is one undo press like every other ripple.

engine/src/project.rs: Project::gap_at (+ private gap()) finds the
empty stretch under a frame, None for inside-a-clip or the open end of
a lane (nothing there to ripple back)
engine/src/playback.rs: PlaybackSession::gap_at forwards it
app/src/menus.rs: ContextMenu::on (Clip|Gap) replaces the clip-only idx
field so the existing menu, its scrim, and every context_menu = None
clear site cover the gap menu for free
app/src/player/timeline_edit.rs: open_gap_menu + close_gap
app/src/ui/overlays.rs: gap branch of context_card renders "Close gap"
app/src/ui/bench_stance.rs: bed's right-click hit-tests gap_at; a click
that lands on a clip leaves that clip's own menu untouched
crates/app/src/menus.rsmodified+19 -5
@@ -2,14 +2,28 @@
22
33 use crate::*;
44
5-/// An open clip menu: which clip it was opened on, where it hangs, and whether
6-/// it has been turned over to show what that clip *is* instead of what can be
7-/// done to it. The lane and index are the ones the same click selected, so
8-/// every item acts on exactly the box under the pointer.
5+/// What a right-click on the bench named: a clip at an index, or the empty
6+/// stretch of the lane it landed in ([`engine::PlaybackSession::gap_at`]) --
7+/// two different things the one menu can be about, so it stays one struct and
8+/// one field to clear rather than a second `Option` beside `context_menu`
9+/// that every closer would have to learn about too.
10+#[derive(Clone, Copy)]
11+pub(crate) enum MenuOn {
12+ Clip(usize),
13+ /// `(start, frames)` of the gap, in timeline frames -- what
14+ /// [`Player::close_gap`] ripples shut.
15+ Gap(u32, u32),
16+}
17+
18+/// An open clip menu: what it was opened on, where it hangs, and whether it
19+/// has been turned over to show what a clip *is* instead of what can be done
20+/// to it (`details` means nothing for a gap, which has no properties side).
21+/// The lane is the one the same click selected, so every item acts on
22+/// exactly the box -- or the hole -- under the pointer.
923 #[derive(Clone, Copy)]
1024 pub(crate) struct ContextMenu {
1125 pub(crate) lane: Lane,
12- pub(crate) idx: usize,
26+ pub(crate) on: MenuOn,
1327 pub(crate) at: Point<Pixels>,
1428 pub(crate) details: bool,
1529 }
crates/app/src/player/timeline_edit.rsmodified+47 -1
@@ -1031,13 +1031,59 @@ impl Player {
10311031 }
10321032 self.context_menu = Some(ContextMenu {
10331033 lane,
1034- idx,
1034+ on: MenuOn::Clip(idx),
10351035 at,
10361036 details: false,
10371037 });
10381038 cx.notify();
10391039 }
10401040
1041+ /// Opens the same menu on the gap under the pointer instead of a clip --
1042+ /// the empty-bench-space door to [`Player::close_gap`]. Nothing is
1043+ /// selected: a gap owns no clip to select, unlike [`Player::open_menu`].
1044+ pub(crate) fn open_gap_menu(&mut self, lane: Lane, start: u32, frames: u32, at: Point<Pixels>, cx: &mut Context<Self>) {
1045+ if self.modal() {
1046+ return;
1047+ }
1048+ self.context_menu = Some(ContextMenu {
1049+ lane,
1050+ on: MenuOn::Gap(start, frames),
1051+ at,
1052+ details: false,
1053+ });
1054+ cx.notify();
1055+ }
1056+
1057+ /// Closes the gap `(start, frames)` on `lane` alone -- Premiere's "Close
1058+ /// Gap", scoped per-lane rather than per-track
1059+ /// ([`engine::PlaybackSession::cut_regions`]): a user after every lane's
1060+ /// gap at once repeats the click on each, while a neighbour that meant to
1061+ /// keep its own silence never moves because this lane's gap closed.
1062+ pub(crate) fn close_gap(&mut self, lane: Lane, start: u32, frames: u32, cx: &mut Context<Self>) {
1063+ let Some(session) = self.session.as_mut() else {
1064+ return;
1065+ };
1066+ match session.cut_regions(&[(start, frames)], &[lane]) {
1067+ Ok(()) => {
1068+ self.mark_dirty();
1069+ // The ripple moves every index after the gap on this lane, the
1070+ // same reason a delete drops the selection.
1071+ self.selected.clear();
1072+ self.reset_after_reseek();
1073+ self.notify_user(
1074+ format!(
1075+ "GAP CLOSED on {} — {} takes it back",
1076+ lane.label(),
1077+ self.keymap.display(ActionId::Undo)
1078+ )
1079+ .into(),
1080+ );
1081+ }
1082+ Err(e) => self.notify_user(e.to_string().into()),
1083+ }
1084+ cx.notify();
1085+ }
1086+
10411087 /// A press on an edge: the start of the drag that changes how much of a
10421088 /// source it plays. It picks the placement as a press anywhere else on the
10431089 /// box does -- the edge strip covers the box's own listener (`occlude`), so
crates/app/src/ui/bench_stance.rsmodified+18 -0
@@ -658,6 +658,24 @@ fn lane_row(
658658 let at = this.place_frame(window.mouse_position().x).0;
659659 this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx)
660660 }))
661+ // Right-click on empty bed space: the "Close Gap" door. A
662+ // clip's own right-click handler (`clip_box`/`sub_box`) never
663+ // stops propagation, so this fires on that press too --
664+ // harmlessly, since `gap_at` answers `None` for a frame a
665+ // clip already covers and this listener does nothing then,
666+ // leaving the clip's own menu exactly as it set it.
667+ .on_mouse_down(
668+ MouseButton::Right,
669+ cx.listener(move |this, event: &MouseDownEvent, _, cx| {
670+ let Some(session) = this.session.as_ref() else {
671+ return;
672+ };
673+ let frame = this.frame_under(event.position.x);
674+ if let Some((start, frames)) = session.gap_at(lane, frame) {
675+ this.open_gap_menu(lane, start, frames, event.position, cx);
676+ }
677+ }),
678+ )
661679 // The landing shadow (`Player::preview_ghost_asset`, the same
662680 // setter `ui/timeline.rs`'s own bed calls) -- guarded on the
663681 // pointer actually being inside this bed's own bounds, since
crates/app/src/ui/overlays.rsmodified+24 -3
@@ -477,7 +477,11 @@ impl Player {
477477 // oracle's either way ([`Ctx::caption`]), so what the card *has* is
478478 // asked for where it is used rather than at the door -- refusing here
479479 // would be a right-click that opens nothing.
480- let clip = session.lane_clips(menu.lane).get(menu.idx).copied();
480+ let idx = match menu.on {
481+ MenuOn::Clip(idx) => Some(idx),
482+ MenuOn::Gap(..) => None,
483+ };
484+ let clip = idx.and_then(|idx| session.lane_clips(menu.lane).get(idx).copied());
481485 let source = clip.and_then(|clip| session.sources().get(clip.source).cloned());
482486 let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps);
483487 // DESIGN §9/§3: a menu row is a plate row, Archivo at the room's
@@ -562,6 +566,22 @@ impl Player {
562566 .into_any_element(),
563567 );
564568 }
569+ } else if let MenuOn::Gap(start, frames) = menu.on {
570+ // The one item a gap offers: no properties, no clip actions, just
571+ // the ripple that closes it -- Premiere's Close Gap, Resolve's
572+ // Delete Gap, per-lane the way `Player::close_gap` documents.
573+ rows.push(
574+ row(rows.len())
575+ .cursor_pointer()
576+ .hover(|s| s.bg(rgb(BG_HOVER())))
577+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
578+ this.context_menu = None;
579+ this.close_gap(menu.lane, start, frames, cx);
580+ }))
581+ .child("Close gap")
582+ .child(chord_style(div().text_color(rgb(FG_SECONDARY()))).child("ripples left"))
583+ .into_any_element(),
584+ );
565585 } else {
566586 // A grade on a waveform, an equalizer on a picture, a silence scan
567587 // on a still: things that do not exist for what was right-clicked,
@@ -570,7 +590,8 @@ impl Player {
570590 // `menu_items`, so there is no second answer to keep in step. The
571591 // state refusals below stay, dimmed and saying why -- the next
572592 // click of the playhead lights them.
573- let ctx = self.ctx(Some((menu.lane, menu.idx)));
593+ let idx = idx.expect("MenuOn::Gap handled above");
594+ let ctx = self.ctx(Some((menu.lane, idx)));
574595 for action in menu_items(ctx) {
575596 // The registry's own answer, the same one the actions card
576597 // dims a row with -- and a row that takes no click says *why*
@@ -627,7 +648,7 @@ impl Player {
627648 // The stroke still steps -- same door.
628649 if action == ActionId::Fit {
629650 this.open_picker(
630- Pick::Fit(menu.lane, menu.idx),
651+ Pick::Fit(menu.lane, idx),
631652 event.position(),
632653 cx,
633654 );
crates/engine/src/playback.rsmodified+7 -0
@@ -2028,6 +2028,13 @@ impl PlaybackSession {
20282028 self.project.lane(lane)
20292029 }
20302030
2031+ /// The empty stretch of `lane` covering `frame`, or `None` when `frame`
2032+ /// is inside a clip or past the last one ([`Project::gap_at`]). What a
2033+ /// right-click on empty bench space asks before offering to close it.
2034+ pub fn gap_at(&self, lane: Lane, frame: u32) -> Option<(u32, u32)> {
2035+ self.project.gap_at(lane, frame)
2036+ }
2037+
20312038 /// Every lane's handle, in display order -- what a front-end lays out top to
20322039 /// bottom, and the list [`add_lane`](Self::add_lane) grows.
20332040 pub fn lanes(&self) -> Vec<Lane> {
crates/engine/src/project.rsmodified+85 -0
@@ -4180,6 +4180,15 @@ impl Project {
41804180 true
41814181 }
41824182
4183+ /// The empty stretch of `lane` covering `frame`, as `(start, len)` -- what
4184+ /// a right-click on empty bench space names before offering to close it.
4185+ /// `None` when `frame` sits inside a clip, or past the last one: the open
4186+ /// end of a lane is not a gap, since there is nothing after it to slide
4187+ /// back ([`gap`]).
4188+ pub fn gap_at(&self, lane: Lane, frame: u32) -> Option<(u32, u32)> {
4189+ gap(self.lane(lane), frame)
4190+ }
4191+
41834192 /// Cut **every** one of `regions` -- `(start, len)` in timeline frames --
41844193 /// out of the lanes in `scope` and close each hole, as one edit: the
41854194 /// jumpcut a silence scan asks for ([`crate::silence`]).
@@ -4899,6 +4908,21 @@ fn at(clips: &[Clip], frame: u32) -> Option<usize> {
48994908 (frame < clips[idx].end()).then_some(idx)
49004909 }
49014910
4911+/// The empty stretch of `clips` covering `frame`, as `(start, len)` -- `None`
4912+/// when `frame` is inside a clip, or past the last one. Sorted-disjoint
4913+/// invariant like [`at`]: the first clip whose start is past `frame` is the
4914+/// far wall, and the last one that ends at or before `frame` (or the
4915+/// timeline's own head, `0`, when there is none) is the near one.
4916+fn gap(clips: &[Clip], frame: u32) -> Option<(u32, u32)> {
4917+ if at(clips, frame).is_some() {
4918+ return None;
4919+ }
4920+ let idx = clips.partition_point(|c| c.start <= frame);
4921+ let next = clips.get(idx)?;
4922+ let start = idx.checked_sub(1).map_or(0, |i| clips[i].end());
4923+ Some((start, next.start - start))
4924+}
4925+
49024926 /// Index of the clip `frame` falls *strictly inside*, i.e. the one a split
49034927 /// there would cut in two. A placement's own first frame is not inside it.
49044928 fn splittable(clips: &[Clip], frame: u32) -> Option<usize> {
@@ -7521,6 +7545,67 @@ mod tests {
75217545 );
75227546 }
75237547
7548+ /// The gap-close menu's hit test: what `gap_at` says about a frame at the
7549+ /// head of a lane, between two clips, inside a clip, past the last one,
7550+ /// and on a lane holding nothing at all.
7551+ #[test]
7552+ fn gap_at_finds_the_hole_a_frame_sits_in() {
7553+ let mut p = Project::single(FILE, 1);
7554+ let v = p.add_lane(LaneKind::Video);
7555+ // Empty lane: nothing before and nothing after -- not a gap, since
7556+ // there is nothing to ripple toward.
7557+ assert_eq!(p.gap_at(v, 0), None, "an empty lane has nothing to close");
7558+
7559+ assert!(p.place(v, 5, clip(5, 0, 3, 0)), "single clip at [5,8)");
7560+ // Before the only clip: the gap runs from the timeline's own head.
7561+ assert_eq!(p.gap_at(v, 0), Some((0, 5)));
7562+ assert_eq!(p.gap_at(v, 4), Some((0, 5)));
7563+ // Inside the clip: not a gap.
7564+ assert_eq!(p.gap_at(v, 5), None);
7565+ assert_eq!(p.gap_at(v, 7), None);
7566+ // Past the only clip: the open end of the lane, not a gap -- there is
7567+ // nothing after it to slide back.
7568+ assert_eq!(p.gap_at(v, 8), None);
7569+ assert_eq!(p.gap_at(v, 100), None);
7570+
7571+ assert!(p.place(v, 12, clip(12, 0, 2, 0)), "a second clip at [12,14)");
7572+ // Between the two: the gap [8,12).
7573+ assert_eq!(p.gap_at(v, 8), Some((8, 4)));
7574+ assert_eq!(p.gap_at(v, 11), Some((8, 4)));
7575+ assert_eq!(p.gap_at(v, 14), None, "still the open end");
7576+
7577+ assert!(
7578+ p.place(v, 8, clip(8, 0, 4, 0)),
7579+ "fills [8,12) exactly, meeting both neighbours"
7580+ );
7581+ assert_eq!(p.gap_at(v, 8), None, "adjacent clips leave no frame to name a gap");
7582+ assert_eq!(p.gap_at(v, 11), None);
7583+ }
7584+
7585+ /// Closing a gap is [`Project::cut_regions`] scoped to the one lane the
7586+ /// menu named: the clip after the gap slides back on that lane, a clip on
7587+ /// another lane at the very same frame range does not move, and the whole
7588+ /// close is one press of undo.
7589+ #[test]
7590+ fn closing_a_gap_ripples_only_its_own_lane_and_undoes_in_one_step() {
7591+ let mut p = Project::single(FILE, 1);
7592+ let v = p.add_lane(LaneKind::Video);
7593+ let a = p.add_lane(LaneKind::Audio);
7594+ assert!(p.place(v, 5, clip(5, 0, 3, 0)), "V clip at [5,8)");
7595+ assert!(
7596+ p.place(a, 0, clip(0, 0, 3, 0)),
7597+ "A clip at [0,3) -- outside the video lane's gap and this scope"
7598+ );
7599+ let before = shape(&p);
7600+ let (start, len) = p.gap_at(v, 0).expect("a gap before the only clip");
7601+ assert_eq!((start, len), (0, 5));
7602+ assert!(p.cut_regions(&[(start, len)], &[v]).is_ok());
7603+ assert_eq!(p.lane(v)[0].start, 0, "the clip slid back to close the gap");
7604+ assert_eq!(p.lane(a)[0].start, 0, "the untouched lane's clip did not move");
7605+ assert!(p.undo(), "one press undoes the whole close");
7606+ assert_eq!(shape(&p), before, "back to exactly where it was");
7607+ }
7608+
75247609 #[test]
75257610 fn ripple_delete_spans_partial_clips() {
75267611 let mut p = three();