From 29d8b28b52042ac087a428bd5904f0015d6957c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 21 Aug 2026 06:22:15 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(timeline):=20a=20right-click?= =?UTF-8?q?=20on=20empty=20bench=20space=20closes=20the=20gap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.rs | 24 ++++++-- crates/app/src/player/timeline_edit.rs | 48 ++++++++++++++- crates/app/src/ui/bench_stance.rs | 18 ++++++ crates/app/src/ui/overlays.rs | 27 +++++++- crates/engine/src/playback.rs | 7 +++ crates/engine/src/project.rs | 85 ++++++++++++++++++++++++++ 6 files changed, 200 insertions(+), 9 deletions(-) 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/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 6a8f8f8..68e4736 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1031,13 +1031,59 @@ 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)` on `lane` alone -- Premiere's "Close + /// Gap", scoped per-lane rather than per-track + /// ([`engine::PlaybackSession::cut_regions`]): a user after every lane's + /// gap at once repeats the click on each, while a neighbour that meant to + /// keep its own silence never moves because this lane's gap closed. + 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; + }; + match session.cut_regions(&[(start, frames)], &[lane]) { + Ok(()) => { + self.mark_dirty(); + // The ripple moves every index after the gap on this lane, the + // same reason a delete drops the selection. + self.selected.clear(); + self.reset_after_reseek(); + self.notify_user( + format!( + "GAP CLOSED on {} — {} takes it back", + lane.label(), + 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/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/engine/src/playback.rs b/crates/engine/src/playback.rs index 5822f1a..a66c56e 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 { diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 1b57300..8ea01c8 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -4180,6 +4180,15 @@ 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) + } + /// 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 +4908,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 +7545,67 @@ 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"); + } + #[test] fn ripple_delete_spans_partial_clips() { let mut p = three();