From cb302ca8ef23fa3081f06c265fd09f3a0a201d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 9 Sep 2026 22:55:53 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(app):=20every=20spine=20verb?= =?UTF-8?q?=20answers=20a=20right-click=20on=20the=20thing=20it=20acts=20o?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rail is going (option C: nothing on screen), so the verbs it listed need the door DESIGN §9 names -- the menu of the thing under the cursor. The clip menu gains the cut machinery (the trim pair, their trim-to-playhead pair and the loop-trim) on the subject cut a right-click already names; the ruler and the empty bench open the timeline's own menu (walking the cuts at either stride, the zoom trio, snap with its state in the row, the undo pair); a lane head opens the track's (the three adds, and the one remove of its own kind, never another lane's). Destructive rows sit under a rule line wherever they are listed, which moved Delete and Lift to the foot of the clip menu. Every row is still an ActionId the keyboard reaches, so label and chord keep coming out of the registry, and `every_verb_the_spine_carried_is_a_right_click_row` fails the moment one of them loses its pointer door again. --- crates/app/src/menus.rs | 70 +++++++++++++++++++++- crates/app/src/oracle.rs | 21 ++++++- crates/app/src/player/timeline_edit.rs | 43 ++++++++++++++ crates/app/src/tests/editing.rs | 80 +++++++++++++++++++++++++- crates/app/src/tests/mod.rs | 6 +- crates/app/src/ui/bench_stance.rs | 48 +++++++++++++++- crates/app/src/ui/overlays.rs | 51 +++++++++++++--- 7 files changed, 299 insertions(+), 20 deletions(-) diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs index 80d2345..9edc9ab 100644 --- a/crates/app/src/menus.rs +++ b/crates/app/src/menus.rs @@ -13,6 +13,15 @@ pub(crate) enum MenuOn { /// `(start, frames)` of the gap, in timeline frames -- what /// [`Player::close_gap`] ripples shut. Gap(u32, u32), + /// The bench itself: the ruler, or the empty stretch below the last lane. + /// Nothing under the pointer is a clip, so what the menu offers is what + /// the *timeline* can be told -- walking its cuts, its zoom, its snap and + /// the undo pair ([`BENCH_ITEMS`]). The lane field means nothing here and + /// no row reads it. + Bench, + /// A lane head: the verbs of the track itself, on the lane the menu + /// already names ([`oracle::lane_items`]). + Head, } /// An open clip menu: what it was opened on, where it hangs, and whether it @@ -179,15 +188,22 @@ impl RowItem { /// action a stroke already reaches -- the menu is a second way *to* the actions /// and never a second version of them -- so both the label and the hint come /// out of the keymap registry and the two can never disagree. -pub(crate) const MENU_ITEMS: [ActionId; 16] = [ +pub(crate) const MENU_ITEMS: [ActionId; 21] = [ ActionId::Cut, + // The cut machinery (DESIGN.md §6) on the very clip it is about: the + // trims, their trim-to-playhead pair and the loop-trim were strokes the + // spine rail listed and nothing else did, and the subject cut a + // right-click names is exactly the one they act on. + ActionId::TrimIn, + ActionId::TrimOut, + ActionId::TrimInToPlayhead, + ActionId::TrimOutToPlayhead, + ActionId::LoopTrim, // The clipboard pair, which had no door but a chord: copy takes the clip the // menu names, and paste is the timeline's rather than this clip's -- the // same kind of global item the mute below already is. ActionId::Copy, ActionId::Paste, - ActionId::Delete, - ActionId::Lift, ActionId::Regroup, ActionId::Detach, ActionId::Group, @@ -205,8 +221,56 @@ pub(crate) const MENU_ITEMS: [ActionId; 16] = [ ActionId::Transform, ActionId::Fit, ActionId::ToggleMute, + // Last, under the rule line the render draws before the first of them + // (DESIGN §9): the two that take the clip off the lane. + ActionId::Delete, + ActionId::Lift, +]; + +/// What a right-click on the bench itself offers -- the ruler and the empty +/// stretch under the lanes. The verbs of the *timeline*: walking its cuts at +/// either stride (DESIGN §6's odometer), what it is looked at through, and the +/// undo pair, which is the one thing every editor expects on empty canvas. +/// Not a junk drawer (§9): nothing here acts on a clip, and everything here +/// acts on the thing the pointer is over. +pub(crate) const BENCH_ITEMS: [ActionId; 10] = [ + ActionId::WalkCutPrev, + ActionId::WalkCutNext, + ActionId::WalkCutPrev10, + ActionId::WalkCutNext10, + ActionId::ZoomOut, + ActionId::ZoomIn, + ActionId::ZoomFit, + ActionId::ToggleSnap, + ActionId::Undo, + ActionId::Redo, ]; +/// The tracks a lane head's menu can add, in the order it lists them. Its +/// remove is the one of the clicked lane's own kind and comes from +/// [`oracle::lane_items`], which is what puts it under the rule line. +pub(crate) const HEAD_ADDS: [ActionId; 3] = [ + ActionId::AddVideoLane, + ActionId::AddAudioLane, + ActionId::AddSubtitleLane, +]; + +/// Whether a menu row takes something away -- what DESIGN §9 puts below a rule +/// line, wherever the row is listed. One answer, so the clip menu and the lane +/// head's menu cannot come to disagree about which of their rows is the +/// dangerous one. +pub(crate) fn destructive(action: ActionId) -> bool { + matches!( + action, + ActionId::Delete + | ActionId::Lift + | ActionId::RemoveVideoLane + | ActionId::RemoveAudioLane + | ActionId::RemoveSubtitleLane + ) +} + + /// One row of the actions card, in the order it lists them: a heading, then /// every action the registry files under it, then the strokes the modal cards /// answer themselves. diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index d7f026d..961c19b 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -314,7 +314,7 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { ActionId::TrimInToPlayhead | ActionId::TrimOutToPlayhead => match ctx.clip { None => Enable::No("no subject cut"), Some((clip, _)) if ctx.playhead < clip.start || ctx.playhead > clip.end() => { - Enable::No("playhead is outside the subject cut") + Enable::No("the playhead is off this cut") } _ => Enable::Yes, }, @@ -358,6 +358,25 @@ pub(crate) fn enable_lane(action: ActionId, lane: Lane, ctx: Ctx) -> Enable { } } +/// The rows a lane head's menu draws: the three tracks a project can gain, +/// and -- under the rule line the render draws before it ([`destructive`]) -- +/// the one remove that means anything on the lane that was right-clicked. A +/// video head never offers to take an audio track off: DESIGN §9's "verbs of +/// the thing under the cursor", read literally. +/// +/// The removes take the *last* track of the kind (the engine's own rule, +/// which their labels say), so this lists at most one of them and never a +/// second row arguing about the same act. +pub(crate) fn lane_items(lane: Lane) -> Vec { + let mut items = HEAD_ADDS.to_vec(); + items.push(match lane.kind { + LaneKind::Video => ActionId::RemoveVideoLane, + LaneKind::Audio => ActionId::RemoveAudioLane, + LaneKind::Subtitle => ActionId::RemoveSubtitleLane, + }); + items +} + /// The rows a clip menu draws, for the clip it was opened on: the registry /// filtered by the one availability oracle, and the *only* way that menu is /// built. An action that means nothing for what was right-clicked -- a grade on diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index c878660..f99b977 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1212,6 +1212,49 @@ impl Player { cx.notify(); } + /// Opens the bench's own menu: what a right-click on the ruler, or on the + /// empty stretch under the last lane, names -- the timeline rather than + /// anything on it ([`BENCH_ITEMS`]). No lane and no selection: the lane + /// field is `V1` because the struct has one, and no row reads it. + /// + /// Refused with no timeline open, like every menu here: a card that paints + /// nothing while `overlaid()` swallows the keys is an invisible modal + /// (`tests/cards.rs`'s FAULT 2 rule). + pub(crate) fn open_bench_menu(&mut self, at: Point, cx: &mut Context) { + if self.modal() || self.session.is_none() { + return; + } + self.context_menu = Some(ContextMenu { + lane: Lane::V1, + on: MenuOn::Bench, + at, + details: false, + }); + cx.notify(); + } + + /// Opens a lane head's menu on the track that was right-clicked: the tracks + /// a project can gain, and the one remove that applies to this lane's kind + /// ([`oracle::lane_items`]). Nothing is selected -- a head owns no clip -- + /// which is [`Player::open_gap_menu`]'s rule on the other empty target. + pub(crate) fn open_head_menu( + &mut self, + lane: Lane, + at: Point, + cx: &mut Context, + ) { + if self.modal() || self.session.is_none() { + return; + } + self.context_menu = Some(ContextMenu { + lane, + on: MenuOn::Head, + 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 diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index d0cc8f0..8162af7 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -335,10 +335,12 @@ fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() { menu_items(cap), vec![ ActionId::Paste, - ActionId::Delete, ActionId::Detach, ActionId::Group, ActionId::ToggleMute, + // Below the rule line the render draws before it, like every + // other row that takes something away (DESIGN §9). + ActionId::Delete, ], "the caption's menu is its removal, its group rows, and the global ones", ); @@ -1964,7 +1966,7 @@ fn trim_to_playhead_needs_a_subject_cut_with_the_playhead_on_it() { }; assert_eq!( enable(ActionId::TrimOutToPlayhead, off), - Enable::No("playhead is outside the subject cut") + Enable::No("the playhead is off this cut") ); let on = Ctx { clip: Some((clip, Lane::V1)), @@ -2720,3 +2722,77 @@ fn escape_with_nothing_open_empties_the_selection() { "bare escape must still route to Deselect for that arm to ever run" ); } + +/// The gate that keeps "option C" honest. The spine rail is gone -- nothing on +/// screen lists these verbs any more -- so every verb it used to carry has to +/// be a row on the menu of the thing it acts on, or it is a verb only a person +/// who already knows its chord can reach. Listed by action id rather than by +/// label, so a reworded row cannot make this pass while the door is gone. +/// +/// And the rule line's own half of DESIGN §9: the destructive rows come last +/// in every list here, which is what lets the render draw one seam before the +/// first of them instead of scattering seams through the plate. +#[test] +fn every_verb_the_spine_carried_is_a_right_click_row() { + use keymap::ActionId; + // The heads a project can have, so the removes are checked on the lane + // each of them belongs to. + let heads: Vec = [Lane::V1, Lane::A1, Lane::S1] + .into_iter() + .flat_map(lane_items) + .collect(); + for (action, menu) in [ + // EDIT + (ActionId::Cut, "clip"), + (ActionId::Lift, "clip"), + (ActionId::Undo, "bench"), + (ActionId::Redo, "bench"), + // CUT + (ActionId::WalkCutPrev, "bench"), + (ActionId::WalkCutNext, "bench"), + (ActionId::WalkCutPrev10, "bench"), + (ActionId::WalkCutNext10, "bench"), + (ActionId::TrimIn, "clip"), + (ActionId::TrimOut, "clip"), + (ActionId::TrimInToPlayhead, "clip"), + (ActionId::TrimOutToPlayhead, "clip"), + (ActionId::LoopTrim, "clip"), + // VIEW + (ActionId::ZoomOut, "bench"), + (ActionId::ZoomIn, "bench"), + (ActionId::ZoomFit, "bench"), + (ActionId::ToggleSnap, "bench"), + // TRACK + (ActionId::AddVideoLane, "lane head"), + (ActionId::AddAudioLane, "lane head"), + (ActionId::AddSubtitleLane, "lane head"), + (ActionId::RemoveVideoLane, "lane head"), + (ActionId::RemoveAudioLane, "lane head"), + (ActionId::RemoveSubtitleLane, "lane head"), + ] { + assert!( + MENU_ITEMS.contains(&action) + || BENCH_ITEMS.contains(&action) + || heads.contains(&action), + "{action:?} reaches no menu: the spine listed it and the {menu} menu does not" + ); + } + // Every menu is a list of actions the keyboard already reaches, so every + // row can wear its chord (DESIGN §4): a row built here out of an id the + // registry never files would print an empty column. + for action in MENU_ITEMS.into_iter().chain(BENCH_ITEMS).chain(heads.iter().copied()) { + assert!( + ActionId::ALL.contains(&action), + "{action:?} is a menu row and not a registered action" + ); + } + for list in [MENU_ITEMS.to_vec(), BENCH_ITEMS.to_vec(), lane_items(Lane::A1)] { + let first = list.iter().position(|&a| destructive(a)); + if let Some(first) = first { + assert!( + list[first..].iter().all(|&a| destructive(a)), + "a safe row sits below the rule line: {list:?}" + ); + } + } +} diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 73d4db3..669eea7 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -16,17 +16,17 @@ use super::{ EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, Enable, BPS_COARSE, BPS_FINE, BPS_MAX, BPS_MIN, EXPORT_MOMENT_H, EncoderSeat, FORMATS, Format, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, KEYS_ROW_H, KEYS_W, KeyRow, LABEL_H, LANE_H, LANES_MAX, LATE_RESYNC, LIBRARY_MAX_W, - LIBRARY_MIN_W, Lane, MB_FLOOR, MENU_ITEMS, MENU_PAD, + BENCH_ITEMS, LIBRARY_MIN_W, Lane, MB_FLOOR, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_W, NO_FILE, NOTICES_MAX, NumberEdit, OVERLAID, PANEL_H, RESYNC_GAP, ROW_ITEMS, RULER_HIT_H, RowCtx, RowItem, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, SUB_PLAN_CHARS, Source, Speed, StreamInfo, TIMELINE_SHARE, Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, Wave, ZOOM_MIN_FRAMES, active_lane, auto_bps, band_label, bitrate_detail, - clipboard_after_remove, color_snap, containers, enable, enable_lane, envelope, eq_card_w, + clipboard_after_remove, color_snap, containers, destructive, enable, enable_lane, envelope, eq_card_w, eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, export_path, export_settings, format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, frame_rate_ladder, histogram, inserted_band, is_project, keymap, keys_rows, lanes_h, - marked, menu_at, menu_items, menu_rows_h, next_container, normalise, nothing_to_play, + lane_items, marked, menu_at, menu_items, menu_rows_h, next_container, normalise, nothing_to_play, notice_tone, panel_h, parse_budget, project_path, range_word, proxies_to_start, push_notice, px_below, retarget, row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label, rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal, diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs index 5bdc16a..973270f 100644 --- a/crates/app/src/ui/bench_stance.rs +++ b/crates/app/src/ui/bench_stance.rs @@ -908,6 +908,15 @@ fn lane_row( cx.new(|_| Tip(head_ghost.clone())) }) .tooltip(crate::ui::widgets::tip_hover("Reorder lane", "drag", None)) + // The head's own verbs, never the bed's: a right-click here + // names the *track* (DESIGN §9), so it opens the lane menu and + // not the clip menu the bed beside it opens. + .on_mouse_down( + MouseButton::Right, + cx.listener(move |this, event: &MouseDownEvent, _, cx| { + this.open_head_menu(lane, event.position, cx); + }), + ) .children(hitmap::dynamic( move || { ( @@ -1120,12 +1129,26 @@ fn lane_row( .on_mouse_down( MouseButton::Right, cx.listener(move |this, event: &MouseDownEvent, _, cx| { + // A clip's (or a caption's) own handler has already run + // by the time this bubbles up and has set its menu: the + // scrim swallows every press while a menu is open, so a + // menu standing here can only be the one this very + // press just opened, and the bed must not replace it. + if this.context_menu.is_some() { + return; + } 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); + match session.gap_at(lane, frame) { + Some((start, frames)) => { + this.open_gap_menu(lane, start, frames, event.position, cx); + } + // Empty bed past the end of the lane's contents: no + // hole to close there, so what the pointer is over + // is the bench itself (DESIGN §9). + None => this.open_bench_menu(event.position, cx), } }), ) @@ -1393,6 +1416,15 @@ pub(crate) fn render( this.scrub_to(event.position.x, true, cx); }), ) + // The bench's own menu, on the strip that *is* the timeline: + // walking the cuts, the zoom, the snap and the undo pair, none + // of which is about a clip (DESIGN §9). + .on_mouse_down( + MouseButton::Right, + cx.listener(|this, event: &MouseDownEvent, _, cx| { + this.open_bench_menu(event.position, cx); + }), + ) .children(ticks.into_iter().map(|(x, label)| { div().absolute().top_0().left(px(x)).child( div() @@ -1480,6 +1512,18 @@ pub(crate) fn render( .child( div() .id("bench-lanes") + // Empty room below the last lane is still the bench: the same + // menu the ruler opens, and the same guard the bed carries -- + // a menu standing here belongs to the press that opened it. + .on_mouse_down( + MouseButton::Right, + cx.listener(|this, event: &MouseDownEvent, _, cx| { + if this.context_menu.is_some() { + return; + } + this.open_bench_menu(event.position, cx); + }), + ) .flex_1() .min_h(px(0.)) .overflow_y_scroll() diff --git a/crates/app/src/ui/overlays.rs b/crates/app/src/ui/overlays.rs index 7541556..79b0a2c 100644 --- a/crates/app/src/ui/overlays.rs +++ b/crates/app/src/ui/overlays.rs @@ -131,7 +131,7 @@ impl Player { // would be a right-click that opens nothing. let idx = match menu.on { MenuOn::Clip(idx) => Some(idx), - MenuOn::Gap(..) => None, + MenuOn::Gap(..) | MenuOn::Bench | MenuOn::Head => 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()); @@ -173,6 +173,8 @@ impl Player { }) }; let mut rows: Vec = Vec::new(); + // Whether the rule line before the destructive rows has been drawn. + let mut ruled = false; if let (true, Some((clip, source))) = (menu.details, clip.zip(source.clone())) { // Read-only, so no ids and no hover: this side is a card, not a // list of things to click. Each value is one truncated line, which @@ -259,9 +261,34 @@ 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 idx = idx.expect("MenuOn::Gap handled above"); - let ctx = self.ctx(Some((menu.lane, idx))); - for action in menu_items(ctx) { + // The clip's own state where a clip was clicked; the editor's + // otherwise -- the bench and the lane head both ask about the + // selection ([`Player::ctx`] falls back to it), which is exactly + // what the cut machinery's rows act on. + let ctx = self.ctx(idx.map(|idx| (menu.lane, idx))); + // Three lists, one render: what the thing under the pointer can be + // told (DESIGN §9). Nothing here is a second version of an action + // -- every row is an [`ActionId`] the keyboard already reaches, so + // the label and the chord still come out of the registry. + let actions = match menu.on { + MenuOn::Bench => BENCH_ITEMS.to_vec(), + MenuOn::Head => lane_items(menu.lane), + _ => menu_items(ctx), + }; + for action in actions { + // DESIGN §9's rule line: the verbs that take something away sit + // under a seam, wherever they are listed. Drawn once, before + // the first of them, and never as the plate's own top edge. + if destructive(action) && !rows.is_empty() && !ruled { + ruled = true; + rows.push( + div() + .my(px(3.)) + .h(px(1.)) + .bg(rgba(DARK_SEAM())) + .into_any_element(), + ); + } // The registry's own answer, the same one the actions card // dims a row with -- and a row that takes no click says *why* // rather than printing a stroke that would do nothing. @@ -286,10 +313,16 @@ impl Player { .or_else(|| full.split_once(" — ").map(|(head, _)| head)) .or_else(|| full.split_once(": ").map(|(head, _)| head)) .unwrap_or(full); - let label = if matches!(action, ActionId::ToggleMute | ActionId::Paste) { - format!("{verb} (global)") - } else { - verb.to_string() + let label = match action { + ActionId::ToggleMute | ActionId::Paste => format!("{verb} (global)"), + // A switch says which way it is set: a row reading "Snap on + // / off" beside a chord tells nobody whether snapping is on + // right now, which is the one thing the spine's badge did + // say before it went. + ActionId::ToggleSnap => { + format!("Snap — {}", if self.snap { "on" } else { "off" }) + } + _ => verb.to_string(), }; let say: SharedString = full.to_string().into(); rows.push( @@ -336,7 +369,7 @@ impl Player { // the list of them on this clip rather than // the next one stepped to behind the click. // The stroke still steps -- same door. - if action == ActionId::Fit { + if let (ActionId::Fit, Some(idx)) = (action, idx) { this.open_picker( Pick::Fit(menu.lane, idx), event.position(),