forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'worktree-agent-a75da909f275c6cda'

Browse files at this commit

88db7f2959f340974017cf4e6da71e4ecd7f24e8Ahmet Kaan GümüşParent: cd9f0dfcc90921
crates/app/src/keymap.rsmodified+30 -3
@@ -45,6 +45,9 @@ pub enum ActionId {
4545 Paste,
4646 Cut,
4747 Regroup,
48+ Select,
49+ SelectNext,
50+ SelectPrev,
4851 Delete,
4952 Lift,
5053 Color,
@@ -63,7 +66,7 @@ pub enum ActionId {
6366 impl ActionId {
6467 /// Display order everywhere -- the editor lists them in it and
6568 /// [`Keymap::defaults`] binds them in it.
66- pub const ALL: [ActionId; 20] = [
69+ pub const ALL: [ActionId; 23] = [
6770 ActionId::Play,
6871 ActionId::Export,
6972 ActionId::Save,
@@ -71,6 +74,9 @@ impl ActionId {
7174 ActionId::Paste,
7275 ActionId::Cut,
7376 ActionId::Regroup,
77+ ActionId::Select,
78+ ActionId::SelectNext,
79+ ActionId::SelectPrev,
7480 ActionId::Delete,
7581 ActionId::Lift,
7682 ActionId::Color,
@@ -96,6 +102,9 @@ impl ActionId {
96102 ActionId::Paste => "Paste",
97103 ActionId::Cut => "Cut",
98104 ActionId::Regroup => "Regroup",
105+ ActionId::Select => "Select the clip under the playhead (again for the next lane)",
106+ ActionId::SelectNext => "Select the next clip in the lane",
107+ ActionId::SelectPrev => "Select the previous clip in the lane",
99108 ActionId::Delete => "Delete",
100109 ActionId::Lift => "Lift (leave a gap)",
101110 ActionId::Color => "Colour…",
@@ -123,6 +132,9 @@ impl ActionId {
123132 ActionId::Paste => "paste",
124133 ActionId::Cut => "cut",
125134 ActionId::Regroup => "regroup",
135+ ActionId::Select => "select",
136+ ActionId::SelectNext => "select-next",
137+ ActionId::SelectPrev => "select-prev",
126138 ActionId::Delete => "delete",
127139 ActionId::Lift => "lift",
128140 ActionId::Color => "color",
@@ -151,6 +163,9 @@ impl ActionId {
151163 ActionId::Play => Category::Playback,
152164 ActionId::Copy
153165 | ActionId::Paste
166+ | ActionId::Select
167+ | ActionId::SelectNext
168+ | ActionId::SelectPrev
154169 | ActionId::Delete
155170 | ActionId::Lift
156171 | ActionId::Color
@@ -384,6 +399,14 @@ impl Keymap {
384399 // The two lane keys, on the letters they are named after: both
385400 // were free, and neither is next to a key that edits.
386401 b(ActionId::Regroup, "g", false),
402+ // Selection without a pointer. Tab is what a keyboard already
403+ // means by "move on to the next thing", and the two brackets
404+ // are the pair either side of it in the lane -- shift+tab is
405+ // the obvious partner and is unspellable here, since a chord
406+ // carries only ctrl and `parse` refuses an uppercase key.
407+ b(ActionId::Select, "tab", false),
408+ b(ActionId::SelectNext, "]", false),
409+ b(ActionId::SelectPrev, "[", false),
387410 b(ActionId::Delete, "x", false),
388411 b(ActionId::Delete, "delete", false),
389412 b(ActionId::Lift, "l", false),
@@ -640,7 +663,7 @@ mod tests {
640663 #[test]
641664 fn every_default_stroke_reaches_its_action() {
642665 let k = Keymap::defaults();
643- assert_eq!(k.entries().len(), 22);
666+ assert_eq!(k.entries().len(), 25);
644667 assert_eq!(k.lookup("space", false), Some(ActionId::Play));
645668 assert_eq!(k.lookup("e", false), Some(ActionId::Export));
646669 assert_eq!(k.lookup("s", true), Some(ActionId::Save));
@@ -648,6 +671,10 @@ mod tests {
648671 assert_eq!(k.lookup("v", true), Some(ActionId::Paste));
649672 assert_eq!(k.lookup("c", false), Some(ActionId::Cut));
650673 assert_eq!(k.lookup("g", false), Some(ActionId::Regroup));
674+ // The keyboard's way onto a clip, and the pair that walks the lane.
675+ assert_eq!(k.lookup("tab", false), Some(ActionId::Select));
676+ assert_eq!(k.lookup("]", false), Some(ActionId::SelectNext));
677+ assert_eq!(k.lookup("[", false), Some(ActionId::SelectPrev));
651678 assert_eq!(k.lookup("x", false), Some(ActionId::Delete));
652679 assert_eq!(k.lookup("delete", false), Some(ActionId::Delete));
653680 assert_eq!(k.lookup("l", false), Some(ActionId::Lift));
@@ -794,7 +821,7 @@ mod tests {
794821 );
795822 // The label is the editor's column, and never the file's word for it.
796823 assert_eq!(ActionId::CancelExport.label(), "Cancel export");
797- assert_eq!(ActionId::ALL.len(), 20);
824+ assert_eq!(ActionId::ALL.len(), 23);
798825 }
799826
800827 #[test]
crates/app/src/main.rsmodified+85 -10
@@ -501,6 +501,9 @@ impl Player {
501501 ActionId::Paste => self.paste(cx),
502502 ActionId::Cut => self.cut(cx),
503503 ActionId::Regroup => self.regroup(cx),
504+ ActionId::Select => self.select_under_playhead(cx),
505+ ActionId::SelectNext => self.select_step(true, cx),
506+ ActionId::SelectPrev => self.select_step(false, cx),
504507 ActionId::Delete => self.delete_selected(cx),
505508 ActionId::Lift => self.lift_selected(cx),
506509 ActionId::Color => self.open_color(cx),
@@ -519,6 +522,73 @@ impl Player {
519522 }
520523 }
521524
525+ /// The one place a clip becomes *the* selected one: a click, a right-click
526+ /// that opens the menu, and every selection key go through here, so what a
527+ /// keyboard marks and what a pointer marks are the same state marked the
528+ /// same way (group and all -- see [`marked`]).
529+ fn select(&mut self, target: (Lane, usize), cx: &mut Context<Self>) {
530+ self.selected = Some(target);
531+ cx.notify();
532+ }
533+
534+ /// Every clip the playhead is over, one per lane, in the order the lanes are
535+ /// drawn -- video first, which is the order [`PlaybackSession::lanes`] comes
536+ /// in. What the select key walks.
537+ fn under_playhead(&self) -> Vec<(Lane, usize)> {
538+ let Some(session) = &self.session else {
539+ return Vec::new();
540+ };
541+ let now = session.now();
542+ session
543+ .lanes()
544+ .into_iter()
545+ .filter_map(|lane| Some((lane, session.lane_clip_at(lane, now)?)))
546+ .collect()
547+ }
548+
549+ /// Selects the clip under the playhead, and on a repeat press the next
550+ /// lane's -- so one key reaches every clip the playhead is over, which is
551+ /// what makes selection (and everything that acts on a selection: delete,
552+ /// lift, the equalizer, the grade) reachable with no pointer at all.
553+ fn select_under_playhead(&mut self, cx: &mut Context<Self>) {
554+ let under = self.under_playhead();
555+ let Some(&first) = under.first() else {
556+ self.notice = Some("NOTHING UNDER THE PLAYHEAD — move it onto a clip first".into());
557+ cx.notify();
558+ return;
559+ };
560+ // Where the current selection sits in that walk decides what "again"
561+ // means; a selection off the playhead starts the walk over.
562+ let next = self
563+ .selected
564+ .and_then(|sel| under.iter().position(|&clip| clip == sel))
565+ .map_or(first, |at| under[(at + 1) % under.len()]);
566+ self.select(next, cx);
567+ }
568+
569+ /// Walks the selection along its own lane, wrapping at either end. Nothing
570+ /// selected means nothing to walk from, so it selects under the playhead
571+ /// exactly as the select key does: either key can start as well as continue.
572+ fn select_step(&mut self, forward: bool, cx: &mut Context<Self>) {
573+ let clips = self
574+ .selected
575+ .zip(self.session.as_ref())
576+ .map_or(0, |((lane, _), session)| session.lane_clips(lane).len());
577+ match (self.selected, clips) {
578+ // An empty lane is a selection nothing can be stepped from -- as is
579+ // no selection at all, and the playhead answers both.
580+ (Some((lane, idx)), len) if len > 0 => {
581+ let next = if forward {
582+ (idx + 1) % len
583+ } else {
584+ (idx + len - 1) % len
585+ };
586+ self.select((lane, next), cx);
587+ }
588+ _ => self.select_under_playhead(cx),
589+ }
590+ }
591+
522592 /// Cycles the fit policy of the clip the picture is coming from -- the
523593 /// clicked one when it is a video clip, else the composite's own, exactly as
524594 /// the colour card picks its target. A whole card for one four-valued
@@ -580,9 +650,9 @@ impl Player {
580650 /// Opens the colour card on the clip a grade would go on: the clip that was
581651 /// clicked when it is a video one, and otherwise the clip the picture is
582652 /// coming from -- the one the engine's own compositing rule picks, which is
583- /// what a person means by "this shot". That fallback is also what makes the
584- /// card reachable with no pointer at all: clip selection is a click and
585- /// nothing else (ledger:182).
653+ /// what a person means by "this shot". The fallback stands even now that a
654+ /// selection key exists: a grade asked for with nothing selected still means
655+ /// the shot on screen.
586656 fn open_color(&mut self, cx: &mut Context<Self>) {
587657 if self.exporting().is_some() {
588658 return;
@@ -669,10 +739,13 @@ impl Player {
669739 return;
670740 }
671741 let refusal = match (self.selected, &self.session) {
672- (_, None) => Some("NO TIMELINE — open a file first"),
673- (None, _) => Some("NOTHING SELECTED — click an audio clip, then ask again"),
742+ (_, None) => Some("NO TIMELINE — open a file first".to_string()),
743+ (None, _) => Some(format!(
744+ "NOTHING SELECTED — click an audio clip or press {}, then ask again",
745+ self.keymap.display(ActionId::Select)
746+ )),
674747 (Some((lane, _)), _) if lane.kind != LaneKind::Audio => Some(
675- "NOT AN AUDIO CLIP — the equalizer works on the sound, so pick a clip in an audio lane",
748+ "NOT AN AUDIO CLIP — the equalizer works on the sound, so pick a clip in an audio lane".to_string(),
676749 ),
677750 _ => None,
678751 };
@@ -3169,7 +3242,10 @@ impl Player {
31693242 let (sel, sel_link) = (self.selected, self.selected_link());
31703243 let audio = lane.kind == LaneKind::Audio;
31713244 let tip: SharedString = format!(
3172- "Select — {} removes the take, {} leaves a gap, {} rejoins a cut",
3245+ "Select (or {} under the playhead, {}/{} along the lane) — {} removes the take, {} leaves a gap, {} rejoins a cut",
3246+ self.keymap.display(ActionId::Select),
3247+ self.keymap.display(ActionId::SelectPrev),
3248+ self.keymap.display(ActionId::SelectNext),
31733249 self.keymap.display(ActionId::Delete),
31743250 self.keymap.display(ActionId::Lift),
31753251 self.keymap.display(ActionId::Regroup)
@@ -3272,8 +3348,7 @@ impl Player {
32723348 .on_mouse_down(
32733349 MouseButton::Left,
32743350 cx.listener(move |this, _: &MouseDownEvent, _, cx| {
3275- this.selected = Some((lane, i));
3276- cx.notify();
3351+ this.select((lane, i), cx);
32773352 }),
32783353 )
32793354 // The right button selects exactly as the left one
@@ -3286,7 +3361,7 @@ impl Player {
32863361 if this.modal() {
32873362 return;
32883363 }
3289- this.selected = Some((lane, i));
3364+ this.select((lane, i), cx);
32903365 this.context_menu = Some(ContextMenu {
32913366 lane,
32923367 idx: i,
crates/engine/src/playback.rsmodified+9 -0
@@ -590,6 +590,15 @@ impl PlaybackSession {
590590 .composite_clip_at(secs_to_frame(timeline_secs, self.meta.frame_rate))
591591 }
592592
593+ /// Which clip of `lane` sits at `timeline_secs`, by the same rule
594+ /// [`video_clip_at`](Self::video_clip_at) picks the picture's with -- per
595+ /// lane, so a keyboard walking the lanes for something to select asks the
596+ /// engine rather than re-deriving where a clip ends.
597+ pub fn lane_clip_at(&self, lane: Lane, timeline_secs: f64) -> Option<usize> {
598+ self.project
599+ .lane_clip_at(lane, secs_to_frame(timeline_secs, self.meta.frame_rate))
600+ }
601+
593602 /// How the clip at `idx` of `lane` is graded, or `None` for one that plays
594603 /// as it was shot -- what a colour card reads when it opens.
595604 pub fn color_of(&self, lane: Lane, idx: usize) -> Option<&ColorParams> {
crates/engine/src/project.rsmodified+28 -0
@@ -842,6 +842,14 @@ impl Project {
842842 Some((video[winner], at(self.lane(video[winner]), timeline_frame)?))
843843 }
844844
845+ /// Which clip of *one* lane `timeline_frame` falls on, or `None` over a gap
846+ /// and past that lane's end. [`composite_clip_at`](Project::composite_clip_at)
847+ /// answers "the clip on screen"; this answers it per lane, which is what
848+ /// walking the lanes for something to select needs.
849+ pub fn lane_clip_at(&self, lane: Lane, timeline_frame: u32) -> Option<usize> {
850+ at(self.lane(lane), timeline_frame)
851+ }
852+
845853 /// How the composite is graded at `timeline_frame`, so the picture playback
846854 /// converts and the one an export encodes are graded from one answer.
847855 /// `None` over a gap (black is black) and for a clip nobody has graded,
@@ -1847,6 +1855,26 @@ mod tests {
18471855 assert_eq!(p.timeline_frames(), 9);
18481856 }
18491857
1858+ /// What a keyboard selection walks: one answer per lane, gaps included --
1859+ /// the composite's own answer is one lane's and cannot say what the audio
1860+ /// lane holds under the same playhead.
1861+ #[test]
1862+ fn lane_clip_at_answers_for_each_lane_separately() {
1863+ let mut p = Project::single(FILE, 9);
1864+ assert!(p.split(3), "both lanes split");
1865+ assert_eq!(p.lane_clip_at(Lane::V1, 0), Some(0));
1866+ assert_eq!(p.lane_clip_at(Lane::V1, 3), Some(1));
1867+ assert_eq!(p.lane_clip_at(Lane::A1, 3), Some(1));
1868+ assert_eq!(p.lane_clip_at(Lane::V1, 9), None, "past the end");
1869+ // A gap on one lane leaves the other's clip selectable there.
1870+ assert!(p.lift(Lane::A1, 0));
1871+ assert_eq!(p.lane_clip_at(Lane::A1, 0), None, "the gap holds nothing");
1872+ assert_eq!(p.lane_clip_at(Lane::A1, 3), Some(0), "indices moved with it");
1873+ assert_eq!(p.lane_clip_at(Lane::V1, 0), Some(0));
1874+ // A lane that is not there is not a panic.
1875+ assert_eq!(p.lane_clip_at(Lane::new(LaneKind::Video, 1), 0), None);
1876+ }
1877+
18501878 #[test]
18511879 fn place_overwrites_only_its_own_lane() {
18521880 let mut p = three();