Mouse_down keeps the selection set so a member drag moves the whole set
Browse files at this commit7b56f0a38069698d23b461657b915d9cefb6cc2fParent: 6c35250- fix
- mouse_down keeps the selection set so a member drag moves the whole set
- click collapses
4 changed files +88 -3
- crates/app/src/player/view.rs +10 -3
- crates/app/src/tests/layout.rs +42 -0
- crates/app/src/ui/bench_stance.rs +18 -0
- crates/app/src/ui/timeline.rs +18 -0
crates/app/src/player/view.rsmodified+10 -3
| @@ -16,12 +16,19 @@ impl Player { | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | /// A press with ctrl held: the pick joins the selection, or leaves it if | 18 | /// A press with ctrl held: the pick joins the selection, or leaves it if |
| 19 | - /// it was already in -- the toggle that assembles a group by hand. Without | 19 | + /// it was already in -- the toggle that assembles a group by hand. |
| 20 | - /// ctrl this is exactly [`Player::select`], which is why every box on the | 20 | + /// Without ctrl, a press on a member of an existing multi-pick keeps the |
| 21 | - /// bed asks this one and lets the modifier decide. | 21 | + /// whole set rather than collapsing it -- collapsing here would make a |
| 22 | + /// set-drag unreachable, since the drag begins on this very press. A | ||
| 23 | + /// plain press anywhere else is exactly [`Player::select`]. Collapsing to | ||
| 24 | + /// the one pressed clip belongs to the click that follows, once it is | ||
| 25 | + /// plain a press and not the start of a drag (see the boxes' own | ||
| 26 | + /// `on_click`), which is why every box on the bed asks this one for the | ||
| 27 | + /// press and its own click listener for the collapse. | ||
| 22 | pub(crate) fn pick(&mut self, target: (Lane, usize), ctrl: bool, cx: &mut Context<Self>) { | 28 | pub(crate) fn pick(&mut self, target: (Lane, usize), ctrl: bool, cx: &mut Context<Self>) { |
| 23 | match ctrl { | 29 | match ctrl { |
| 24 | true => self.selected.toggle(target), | 30 | true => self.selected.toggle(target), |
| 31 | + false if self.selected.contains(target) => {} | ||
| 25 | false => self.selected.set_one(target), | 32 | false => self.selected.set_one(target), |
| 26 | } | 33 | } |
| 27 | cx.notify(); | 34 | cx.notify(); |
crates/app/src/tests/layout.rsmodified+42 -0
| @@ -654,6 +654,48 @@ fn a_selection_holds_its_picks_in_click_order_and_anchors_the_last() { | |||
| 654 | assert_eq!(sel.anchor(), None); | 654 | assert_eq!(sel.anchor(), None); |
| 655 | } | 655 | } |
| 656 | 656 | ||
| 657 | +/// `Player::pick`'s own decision, mirrored here against `Selection` alone | ||
| 658 | +/// (`pick` itself needs a `Context<Player>` this module has no window to | ||
| 659 | +/// build): a plain press on a clip already in a multi-pick must leave the | ||
| 660 | +/// set alone, since the press is where a set-drag begins -- collapsing here | ||
| 661 | +/// would make dragging a member of a selection move only that one clip. | ||
| 662 | +/// Collapsing to the one pressed belongs to a plain click, once it is a | ||
| 663 | +/// click and not a drag (`ui/bench_stance.rs`/`ui/timeline.rs`'s `on_click`). | ||
| 664 | +#[test] | ||
| 665 | +fn a_plain_press_on_an_already_picked_clip_keeps_the_set() { | ||
| 666 | + use crate::Selection; | ||
| 667 | + | ||
| 668 | + let (v, a, cap) = ( | ||
| 669 | + (Lane::V1, 0), | ||
| 670 | + (Lane::A1, 0), | ||
| 671 | + (Lane::new(LaneKind::Subtitle, 0), 0), | ||
| 672 | + ); | ||
| 673 | + let mut sel = Selection::new(); | ||
| 674 | + sel.toggle(v); | ||
| 675 | + sel.toggle(a); | ||
| 676 | + sel.toggle(cap); | ||
| 677 | + assert_eq!(sel.picks(), &[v, a, cap]); | ||
| 678 | + | ||
| 679 | + let press = |sel: &mut Selection, target, ctrl| match ctrl { | ||
| 680 | + true => sel.toggle(target), | ||
| 681 | + false if sel.contains(target) => {} | ||
| 682 | + false => sel.set_one(target), | ||
| 683 | + }; | ||
| 684 | + | ||
| 685 | + press(&mut sel, a, false); | ||
| 686 | + assert_eq!( | ||
| 687 | + sel.picks(), | ||
| 688 | + &[v, a, cap], | ||
| 689 | + "a plain press on a member of the set keeps it, for a set-drag to move" | ||
| 690 | + ); | ||
| 691 | + | ||
| 692 | + // A plain press on something outside the set still collapses to it -- | ||
| 693 | + // the ordinary single-select case. | ||
| 694 | + let outside = (Lane::V1, 1); | ||
| 695 | + press(&mut sel, outside, false); | ||
| 696 | + assert_eq!(sel.picks(), &[outside]); | ||
| 697 | +} | ||
| 698 | + | ||
| 657 | #[test] | 699 | #[test] |
| 658 | fn a_click_marks_the_whole_group_and_nothing_else() { | 700 | fn a_click_marks_the_whole_group_and_nothing_else() { |
| 659 | let (v, a) = ((Lane::V1, 0), (Lane::A1, 0)); | 701 | let (v, a) = ((Lane::V1, 0), (Lane::A1, 0)); |
crates/app/src/ui/bench_stance.rsmodified+18 -0
| @@ -281,6 +281,17 @@ fn clip_box( | |||
| 281 | this.pick((lane, idx), event.modifiers.control, cx); | 281 | this.pick((lane, idx), event.modifiers.control, cx); |
| 282 | }), | 282 | }), |
| 283 | ) | 283 | ) |
| 284 | + // A plain click (press and release with no drag between -- gpui | ||
| 285 | + // drops the pending click once a drag starts, see `on_drag` below) | ||
| 286 | + // collapses a multi-pick down to the one clicked, the same way | ||
| 287 | + // `select` does. `pick` above deliberately keeps the whole set on | ||
| 288 | + // the press so a set-drag has something to move; this is where the | ||
| 289 | + // collapse a plain click promises actually lands. | ||
| 290 | + .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { | ||
| 291 | + if !event.modifiers().control { | ||
| 292 | + this.select((lane, idx), cx); | ||
| 293 | + } | ||
| 294 | + })) | ||
| 284 | // The right button selects exactly as the left one does -- the menu | 295 | // The right button selects exactly as the left one does -- the menu |
| 285 | // acts on the clip it names -- then hangs the clip menu at the | 296 | // acts on the clip it names -- then hangs the clip menu at the |
| 286 | // pointer (DESIGN §9's "verbs of the thing under the cursor"). Same | 297 | // pointer (DESIGN §9's "verbs of the thing under the cursor"). Same |
| @@ -658,6 +669,13 @@ fn sub_box( | |||
| 658 | this.pick((lane, idx), event.modifiers.control, cx); | 669 | this.pick((lane, idx), event.modifiers.control, cx); |
| 659 | }), | 670 | }), |
| 660 | ) | 671 | ) |
| 672 | + // A plain click collapses a multi-pick to this one, exactly as a | ||
| 673 | + // clip's own box does -- see the comment there. | ||
| 674 | + .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { | ||
| 675 | + if !event.modifiers().control { | ||
| 676 | + this.select((lane, idx), cx); | ||
| 677 | + } | ||
| 678 | + })) | ||
| 661 | // Same door a clip's box opens its menu by (DESIGN §9). | 679 | // Same door a clip's box opens its menu by (DESIGN §9). |
| 662 | .on_mouse_down( | 680 | .on_mouse_down( |
| 663 | MouseButton::Right, | 681 | MouseButton::Right, |
crates/app/src/ui/timeline.rsmodified+18 -0
| @@ -1383,6 +1383,17 @@ impl Player { | |||
| 1383 | this.pick((lane, i), event.modifiers.control, cx); | 1383 | this.pick((lane, i), event.modifiers.control, cx); |
| 1384 | }), | 1384 | }), |
| 1385 | ) | 1385 | ) |
| 1386 | + // A plain click collapses a multi-pick to this one | ||
| 1387 | + // clip -- `pick` above deliberately keeps the whole | ||
| 1388 | + // set on the press so a set-drag has something to | ||
| 1389 | + // move; gpui drops the pending click once a drag | ||
| 1390 | + // starts, so this only fires on a press-release | ||
| 1391 | + // with no drag between. | ||
| 1392 | + .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { | ||
| 1393 | + if !event.modifiers().control { | ||
| 1394 | + this.select((lane, i), cx); | ||
| 1395 | + } | ||
| 1396 | + })) | ||
| 1386 | // The right button selects exactly as the left one | 1397 | // The right button selects exactly as the left one |
| 1387 | // does -- the menu acts on the clip it names, so | 1398 | // does -- the menu acts on the clip it names, so |
| 1388 | // opening one has to pick it -- and then hangs the | 1399 | // opening one has to pick it -- and then hangs the |
| @@ -1761,6 +1772,13 @@ impl Player { | |||
| 1761 | this.pick((lane, i), event.modifiers.control, cx); | 1772 | this.pick((lane, i), event.modifiers.control, cx); |
| 1762 | }), | 1773 | }), |
| 1763 | ) | 1774 | ) |
| 1775 | + // A plain click collapses a multi-pick to this one | ||
| 1776 | + // caption, exactly as a clip's own box does above. | ||
| 1777 | + .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| { | ||
| 1778 | + if !event.modifiers().control { | ||
| 1779 | + this.select((lane, i), cx); | ||
| 1780 | + } | ||
| 1781 | + })) | ||
| 1764 | // The right button marks it and hangs the menu at | 1782 | // The right button marks it and hangs the menu at |
| 1765 | // the pointer, the clip menu opened on the clip | 1783 | // the pointer, the clip menu opened on the clip |
| 1766 | // box's own rule -- the Delete row of it is this | 1784 | // box's own rule -- the Delete row of it is this |