diff --git a/crates/app/src/player/view.rs b/crates/app/src/player/view.rs index 9ac4eaf..d8c750f 100644 --- a/crates/app/src/player/view.rs +++ b/crates/app/src/player/view.rs @@ -16,12 +16,19 @@ impl Player { } /// A press with ctrl held: the pick joins the selection, or leaves it if - /// it was already in -- the toggle that assembles a group by hand. Without - /// ctrl this is exactly [`Player::select`], which is why every box on the - /// bed asks this one and lets the modifier decide. + /// it was already in -- the toggle that assembles a group by hand. + /// Without ctrl, a press on a member of an existing multi-pick keeps the + /// whole set rather than collapsing it -- collapsing here would make a + /// set-drag unreachable, since the drag begins on this very press. A + /// plain press anywhere else is exactly [`Player::select`]. Collapsing to + /// the one pressed clip belongs to the click that follows, once it is + /// plain a press and not the start of a drag (see the boxes' own + /// `on_click`), which is why every box on the bed asks this one for the + /// press and its own click listener for the collapse. pub(crate) fn pick(&mut self, target: (Lane, usize), ctrl: bool, cx: &mut Context) { match ctrl { true => self.selected.toggle(target), + false if self.selected.contains(target) => {} false => self.selected.set_one(target), } cx.notify(); diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index e297058..e4857ea 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -654,6 +654,48 @@ fn a_selection_holds_its_picks_in_click_order_and_anchors_the_last() { assert_eq!(sel.anchor(), None); } +/// `Player::pick`'s own decision, mirrored here against `Selection` alone +/// (`pick` itself needs a `Context` this module has no window to +/// build): a plain press on a clip already in a multi-pick must leave the +/// set alone, since the press is where a set-drag begins -- collapsing here +/// would make dragging a member of a selection move only that one clip. +/// Collapsing to the one pressed belongs to a plain click, once it is a +/// click and not a drag (`ui/bench_stance.rs`/`ui/timeline.rs`'s `on_click`). +#[test] +fn a_plain_press_on_an_already_picked_clip_keeps_the_set() { + use crate::Selection; + + let (v, a, cap) = ( + (Lane::V1, 0), + (Lane::A1, 0), + (Lane::new(LaneKind::Subtitle, 0), 0), + ); + let mut sel = Selection::new(); + sel.toggle(v); + sel.toggle(a); + sel.toggle(cap); + assert_eq!(sel.picks(), &[v, a, cap]); + + let press = |sel: &mut Selection, target, ctrl| match ctrl { + true => sel.toggle(target), + false if sel.contains(target) => {} + false => sel.set_one(target), + }; + + press(&mut sel, a, false); + assert_eq!( + sel.picks(), + &[v, a, cap], + "a plain press on a member of the set keeps it, for a set-drag to move" + ); + + // A plain press on something outside the set still collapses to it -- + // the ordinary single-select case. + let outside = (Lane::V1, 1); + press(&mut sel, outside, false); + assert_eq!(sel.picks(), &[outside]); +} + #[test] fn a_click_marks_the_whole_group_and_nothing_else() { let (v, a) = ((Lane::V1, 0), (Lane::A1, 0)); diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs index 87c8d9b..b53e58b 100644 --- a/crates/app/src/ui/bench_stance.rs +++ b/crates/app/src/ui/bench_stance.rs @@ -281,6 +281,17 @@ fn clip_box( this.pick((lane, idx), event.modifiers.control, cx); }), ) + // A plain click (press and release with no drag between -- gpui + // drops the pending click once a drag starts, see `on_drag` below) + // collapses a multi-pick down to the one clicked, the same way + // `select` does. `pick` above deliberately keeps the whole set on + // the press so a set-drag has something to move; this is where the + // collapse a plain click promises actually lands. + .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { + if !event.modifiers().control { + this.select((lane, idx), cx); + } + })) // The right button selects exactly as the left one does -- the menu // acts on the clip it names -- then hangs the clip menu at the // pointer (DESIGN §9's "verbs of the thing under the cursor"). Same @@ -658,6 +669,13 @@ fn sub_box( this.pick((lane, idx), event.modifiers.control, cx); }), ) + // A plain click collapses a multi-pick to this one, exactly as a + // clip's own box does -- see the comment there. + .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { + if !event.modifiers().control { + this.select((lane, idx), cx); + } + })) // Same door a clip's box opens its menu by (DESIGN §9). .on_mouse_down( MouseButton::Right, diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 6470b11..b5c0de2 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -1383,6 +1383,17 @@ impl Player { this.pick((lane, i), event.modifiers.control, cx); }), ) + // A plain click collapses a multi-pick to this one + // clip -- `pick` above deliberately keeps the whole + // set on the press so a set-drag has something to + // move; gpui drops the pending click once a drag + // starts, so this only fires on a press-release + // with no drag between. + .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { + if !event.modifiers().control { + this.select((lane, i), cx); + } + })) // The right button selects exactly as the left one // does -- the menu acts on the clip it names, so // opening one has to pick it -- and then hangs the @@ -1761,6 +1772,13 @@ impl Player { this.pick((lane, i), event.modifiers.control, cx); }), ) + // A plain click collapses a multi-pick to this one + // caption, exactly as a clip's own box does above. + .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { + if !event.modifiers().control { + this.select((lane, i), cx); + } + })) // The right button marks it and hangs the menu at // the pointer, the clip menu opened on the clip // box's own rule -- the Delete row of it is this