From cc90921f0aa4194ce5e539fc791a6b5bc48bea7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 10 Aug 2026 13:03:40 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(timeline):=20clips=20select=20?= =?UTF-8?q?from=20the=20keyboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tab selects the clip under the playhead -- again for the next lane's -- and [ / ] walk the selection along its own lane, wrapping at both ends. shift+tab stays unspellable (a chord carries only ctrl and parse refuses an uppercase key), so the brackets are the pair. One selection and not a second: every door -- click, right-click, all three keys -- goes through Player::select, so the group-scoped tint a click draws is the tint a key draws. Project::lane_clip_at is what the walk asks, per lane, rather than the UI re-deriving where a clip ends. This is what makes delete, lift, the equalizer and the grade reachable with no pointer at all: the equalizer card had never been rendered live, because nothing but a click could select the audio clip it needs. --- crates/app/src/keymap.rs | 33 ++++++++++-- crates/app/src/main.rs | 95 +++++++++++++++++++++++++++++++---- crates/engine/src/playback.rs | 9 ++++ crates/engine/src/project.rs | 28 +++++++++++ 4 files changed, 152 insertions(+), 13 deletions(-) diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 87200b9..977ae4a 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -45,6 +45,9 @@ pub enum ActionId { Paste, Cut, Regroup, + Select, + SelectNext, + SelectPrev, Delete, Lift, Color, @@ -63,7 +66,7 @@ pub enum ActionId { impl ActionId { /// Display order everywhere -- the editor lists them in it and /// [`Keymap::defaults`] binds them in it. - pub const ALL: [ActionId; 20] = [ + pub const ALL: [ActionId; 23] = [ ActionId::Play, ActionId::Export, ActionId::Save, @@ -71,6 +74,9 @@ impl ActionId { ActionId::Paste, ActionId::Cut, ActionId::Regroup, + ActionId::Select, + ActionId::SelectNext, + ActionId::SelectPrev, ActionId::Delete, ActionId::Lift, ActionId::Color, @@ -96,6 +102,9 @@ impl ActionId { ActionId::Paste => "Paste", ActionId::Cut => "Cut", ActionId::Regroup => "Regroup", + ActionId::Select => "Select the clip under the playhead (again for the next lane)", + ActionId::SelectNext => "Select the next clip in the lane", + ActionId::SelectPrev => "Select the previous clip in the lane", ActionId::Delete => "Delete", ActionId::Lift => "Lift (leave a gap)", ActionId::Color => "Colour…", @@ -123,6 +132,9 @@ impl ActionId { ActionId::Paste => "paste", ActionId::Cut => "cut", ActionId::Regroup => "regroup", + ActionId::Select => "select", + ActionId::SelectNext => "select-next", + ActionId::SelectPrev => "select-prev", ActionId::Delete => "delete", ActionId::Lift => "lift", ActionId::Color => "color", @@ -151,6 +163,9 @@ impl ActionId { ActionId::Play => Category::Playback, ActionId::Copy | ActionId::Paste + | ActionId::Select + | ActionId::SelectNext + | ActionId::SelectPrev | ActionId::Delete | ActionId::Lift | ActionId::Color @@ -384,6 +399,14 @@ impl Keymap { // The two lane keys, on the letters they are named after: both // were free, and neither is next to a key that edits. b(ActionId::Regroup, "g", false), + // Selection without a pointer. Tab is what a keyboard already + // means by "move on to the next thing", and the two brackets + // are the pair either side of it in the lane -- shift+tab is + // the obvious partner and is unspellable here, since a chord + // carries only ctrl and `parse` refuses an uppercase key. + b(ActionId::Select, "tab", false), + b(ActionId::SelectNext, "]", false), + b(ActionId::SelectPrev, "[", false), b(ActionId::Delete, "x", false), b(ActionId::Delete, "delete", false), b(ActionId::Lift, "l", false), @@ -640,7 +663,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 22); + assert_eq!(k.entries().len(), 25); assert_eq!(k.lookup("space", false), Some(ActionId::Play)); assert_eq!(k.lookup("e", false), Some(ActionId::Export)); assert_eq!(k.lookup("s", true), Some(ActionId::Save)); @@ -648,6 +671,10 @@ mod tests { assert_eq!(k.lookup("v", true), Some(ActionId::Paste)); assert_eq!(k.lookup("c", false), Some(ActionId::Cut)); assert_eq!(k.lookup("g", false), Some(ActionId::Regroup)); + // The keyboard's way onto a clip, and the pair that walks the lane. + assert_eq!(k.lookup("tab", false), Some(ActionId::Select)); + assert_eq!(k.lookup("]", false), Some(ActionId::SelectNext)); + assert_eq!(k.lookup("[", false), Some(ActionId::SelectPrev)); assert_eq!(k.lookup("x", false), Some(ActionId::Delete)); assert_eq!(k.lookup("delete", false), Some(ActionId::Delete)); assert_eq!(k.lookup("l", false), Some(ActionId::Lift)); @@ -794,7 +821,7 @@ mod tests { ); // The label is the editor's column, and never the file's word for it. assert_eq!(ActionId::CancelExport.label(), "Cancel export"); - assert_eq!(ActionId::ALL.len(), 20); + assert_eq!(ActionId::ALL.len(), 23); } #[test] diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 71859ef..b4f852c 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -501,6 +501,9 @@ impl Player { ActionId::Paste => self.paste(cx), ActionId::Cut => self.cut(cx), ActionId::Regroup => self.regroup(cx), + ActionId::Select => self.select_under_playhead(cx), + ActionId::SelectNext => self.select_step(true, cx), + ActionId::SelectPrev => self.select_step(false, cx), ActionId::Delete => self.delete_selected(cx), ActionId::Lift => self.lift_selected(cx), ActionId::Color => self.open_color(cx), @@ -519,6 +522,73 @@ impl Player { } } + /// The one place a clip becomes *the* selected one: a click, a right-click + /// that opens the menu, and every selection key go through here, so what a + /// keyboard marks and what a pointer marks are the same state marked the + /// same way (group and all -- see [`marked`]). + fn select(&mut self, target: (Lane, usize), cx: &mut Context) { + self.selected = Some(target); + cx.notify(); + } + + /// Every clip the playhead is over, one per lane, in the order the lanes are + /// drawn -- video first, which is the order [`PlaybackSession::lanes`] comes + /// in. What the select key walks. + fn under_playhead(&self) -> Vec<(Lane, usize)> { + let Some(session) = &self.session else { + return Vec::new(); + }; + let now = session.now(); + session + .lanes() + .into_iter() + .filter_map(|lane| Some((lane, session.lane_clip_at(lane, now)?))) + .collect() + } + + /// Selects the clip under the playhead, and on a repeat press the next + /// lane's -- so one key reaches every clip the playhead is over, which is + /// what makes selection (and everything that acts on a selection: delete, + /// lift, the equalizer, the grade) reachable with no pointer at all. + fn select_under_playhead(&mut self, cx: &mut Context) { + let under = self.under_playhead(); + let Some(&first) = under.first() else { + self.notice = Some("NOTHING UNDER THE PLAYHEAD — move it onto a clip first".into()); + cx.notify(); + return; + }; + // Where the current selection sits in that walk decides what "again" + // means; a selection off the playhead starts the walk over. + let next = self + .selected + .and_then(|sel| under.iter().position(|&clip| clip == sel)) + .map_or(first, |at| under[(at + 1) % under.len()]); + self.select(next, cx); + } + + /// Walks the selection along its own lane, wrapping at either end. Nothing + /// selected means nothing to walk from, so it selects under the playhead + /// exactly as the select key does: either key can start as well as continue. + fn select_step(&mut self, forward: bool, cx: &mut Context) { + let clips = self + .selected + .zip(self.session.as_ref()) + .map_or(0, |((lane, _), session)| session.lane_clips(lane).len()); + match (self.selected, clips) { + // An empty lane is a selection nothing can be stepped from -- as is + // no selection at all, and the playhead answers both. + (Some((lane, idx)), len) if len > 0 => { + let next = if forward { + (idx + 1) % len + } else { + (idx + len - 1) % len + }; + self.select((lane, next), cx); + } + _ => self.select_under_playhead(cx), + } + } + /// Cycles the fit policy of the clip the picture is coming from -- the /// clicked one when it is a video clip, else the composite's own, exactly as /// the colour card picks its target. A whole card for one four-valued @@ -580,9 +650,9 @@ impl Player { /// Opens the colour card on the clip a grade would go on: the clip that was /// clicked when it is a video one, and otherwise the clip the picture is /// coming from -- the one the engine's own compositing rule picks, which is - /// what a person means by "this shot". That fallback is also what makes the - /// card reachable with no pointer at all: clip selection is a click and - /// nothing else (ledger:182). + /// what a person means by "this shot". The fallback stands even now that a + /// selection key exists: a grade asked for with nothing selected still means + /// the shot on screen. fn open_color(&mut self, cx: &mut Context) { if self.exporting().is_some() { return; @@ -669,10 +739,13 @@ impl Player { return; } let refusal = match (self.selected, &self.session) { - (_, None) => Some("NO TIMELINE — open a file first"), - (None, _) => Some("NOTHING SELECTED — click an audio clip, then ask again"), + (_, None) => Some("NO TIMELINE — open a file first".to_string()), + (None, _) => Some(format!( + "NOTHING SELECTED — click an audio clip or press {}, then ask again", + self.keymap.display(ActionId::Select) + )), (Some((lane, _)), _) if lane.kind != LaneKind::Audio => Some( - "NOT AN AUDIO CLIP — the equalizer works on the sound, so pick a clip in an audio lane", + "NOT AN AUDIO CLIP — the equalizer works on the sound, so pick a clip in an audio lane".to_string(), ), _ => None, }; @@ -3169,7 +3242,10 @@ impl Player { let (sel, sel_link) = (self.selected, self.selected_link()); let audio = lane.kind == LaneKind::Audio; let tip: SharedString = format!( - "Select — {} removes the take, {} leaves a gap, {} rejoins a cut", + "Select (or {} under the playhead, {}/{} along the lane) — {} removes the take, {} leaves a gap, {} rejoins a cut", + self.keymap.display(ActionId::Select), + self.keymap.display(ActionId::SelectPrev), + self.keymap.display(ActionId::SelectNext), self.keymap.display(ActionId::Delete), self.keymap.display(ActionId::Lift), self.keymap.display(ActionId::Regroup) @@ -3272,8 +3348,7 @@ impl Player { .on_mouse_down( MouseButton::Left, cx.listener(move |this, _: &MouseDownEvent, _, cx| { - this.selected = Some((lane, i)); - cx.notify(); + this.select((lane, i), cx); }), ) // The right button selects exactly as the left one @@ -3286,7 +3361,7 @@ impl Player { if this.modal() { return; } - this.selected = Some((lane, i)); + this.select((lane, i), cx); this.context_menu = Some(ContextMenu { lane, idx: i, diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 90853cd..a0d95fa 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -590,6 +590,15 @@ impl PlaybackSession { .composite_clip_at(secs_to_frame(timeline_secs, self.meta.frame_rate)) } + /// Which clip of `lane` sits at `timeline_secs`, by the same rule + /// [`video_clip_at`](Self::video_clip_at) picks the picture's with -- per + /// lane, so a keyboard walking the lanes for something to select asks the + /// engine rather than re-deriving where a clip ends. + pub fn lane_clip_at(&self, lane: Lane, timeline_secs: f64) -> Option { + self.project + .lane_clip_at(lane, secs_to_frame(timeline_secs, self.meta.frame_rate)) + } + /// How the clip at `idx` of `lane` is graded, or `None` for one that plays /// as it was shot -- what a colour card reads when it opens. pub fn color_of(&self, lane: Lane, idx: usize) -> Option<&ColorParams> { diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 77a0d72..56e2e02 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -842,6 +842,14 @@ impl Project { Some((video[winner], at(self.lane(video[winner]), timeline_frame)?)) } + /// Which clip of *one* lane `timeline_frame` falls on, or `None` over a gap + /// and past that lane's end. [`composite_clip_at`](Project::composite_clip_at) + /// answers "the clip on screen"; this answers it per lane, which is what + /// walking the lanes for something to select needs. + pub fn lane_clip_at(&self, lane: Lane, timeline_frame: u32) -> Option { + at(self.lane(lane), timeline_frame) + } + /// How the composite is graded at `timeline_frame`, so the picture playback /// converts and the one an export encodes are graded from one answer. /// `None` over a gap (black is black) and for a clip nobody has graded, @@ -1847,6 +1855,26 @@ mod tests { assert_eq!(p.timeline_frames(), 9); } + /// What a keyboard selection walks: one answer per lane, gaps included -- + /// the composite's own answer is one lane's and cannot say what the audio + /// lane holds under the same playhead. + #[test] + fn lane_clip_at_answers_for_each_lane_separately() { + let mut p = Project::single(FILE, 9); + assert!(p.split(3), "both lanes split"); + assert_eq!(p.lane_clip_at(Lane::V1, 0), Some(0)); + assert_eq!(p.lane_clip_at(Lane::V1, 3), Some(1)); + assert_eq!(p.lane_clip_at(Lane::A1, 3), Some(1)); + assert_eq!(p.lane_clip_at(Lane::V1, 9), None, "past the end"); + // A gap on one lane leaves the other's clip selectable there. + assert!(p.lift(Lane::A1, 0)); + assert_eq!(p.lane_clip_at(Lane::A1, 0), None, "the gap holds nothing"); + assert_eq!(p.lane_clip_at(Lane::A1, 3), Some(0), "indices moved with it"); + assert_eq!(p.lane_clip_at(Lane::V1, 0), Some(0)); + // A lane that is not there is not a panic. + assert_eq!(p.lane_clip_at(Lane::new(LaneKind::Video, 1), 0), None); + } + #[test] fn place_overwrites_only_its_own_lane() { let mut p = three();