Selection: widget drags read the release point and a tool switch cancels them

A drag of a corner, pie or blend widget, an Objects on Path widget, a
bracket of type on a path or a 9-slice guide released away from its last
drag event now drags there before it ends, so the release keeps what a
drag to that point would show. The Objects on Path tool reads the release
the same way.

Switching tools during a drag of an Objects on Path widget, a bracket, a
repeat control or a 9-slice guide now cancels it, as Escape does, in the
Selection tool and the Objects on Path tool. Before, the preview stayed
open after the tool was gone.
This commit is contained in:
dotCooCoo committed 2026-11-18 16:40:59 -08:00
1 parent bab45a99f3
commit e3ccd346ad
10 files changed
+282 -23

No files matched your search

+11 -1
View File
@@ -512,7 +512,7 @@ mod tests {
assert_eq!(a, vec![Action::Preview("object.blend.setEasing".into(), json!({"id": id.0, "ramp": 0.0}))], "clamped at 0");
let a = t.pointer(&c, &ev(PointerKind::Drag, at + Vec2::new(500.0, 0.0)));
assert_eq!(a, vec![Action::Preview("object.blend.setEasing".into(), json!({"id": id.0, "ramp": 100.0}))], "clamped at 100");
assert_eq!(t.pointer(&c, &ev(PointerKind::Up, at)), vec![Action::Commit]);
assert_eq!(t.pointer(&c, &ev(PointerKind::Up, at + Vec2::new(500.0, 0.0))), vec![Action::Commit]);
// A click that doesn't move sends nothing.
assert!(t.pointer(&c, &ev(PointerKind::Down, at)).is_empty());
assert!(t.pointer(&c, &ev(PointerKind::Up, at)).is_empty());
@@ -546,6 +546,16 @@ mod tests {
assert_eq!(a[1], Action::Preview("object.blend.setEasing".into(), json!({"id": id.0, "ramp": 50.0})));
}
/// A drag with the Selection tool reads where it is released, and a tool switch cancels it.
#[test]
fn a_drag_reads_its_release() {
let (d, _, s) = blend_doc(&[(100.0, 200.0), (300.0, 200.0)], eased());
let p = paint();
let c = cx(&d, &s, &p);
let at = Point::new(200.0, 216.0);
check_widget_release_and_tool_switch(&c, at, at + Vec2::new(20.0, 0.0), at + Vec2::new(40.0, 0.0));
}
/// Switching away from the Selection or Blend tool during a drag cancels it, and after a press
/// that has not moved there is nothing to put back.
#[test]
+20
View File
@@ -600,6 +600,26 @@ pub(crate) mod testutil {
PaintDefaults::default()
}
/// With the Selection tool, a widget pressed at `at` and dragged to `q`, then released at `r`, is
/// dragged to `r` before the drag ends: the release keeps what a drag to `r` shows. Switching
/// tools during the drag cancels it, and the release after it commits nothing.
pub fn check_widget_release_and_tool_switch(cx: &ToolContext, at: Point, q: Point, r: Point) {
let pressed = || {
let mut t = crate::select::SelectionTool::default();
t.pointer(cx, &PointerEvent::new(PointerKind::Down, at.x, at.y));
assert!(!t.pointer(cx, &PointerEvent::new(PointerKind::Drag, q.x, q.y)).is_empty(), "the drag to {q:?} changes the widget");
t
};
let mut want = pressed().pointer(cx, &PointerEvent::new(PointerKind::Drag, r.x, r.y));
assert!(!want.is_empty(), "the drag to {r:?} changes the widget");
want.push(Action::Commit);
assert_eq!(pressed().pointer(cx, &PointerEvent::new(PointerKind::Up, r.x, r.y)), want, "released at {r:?}");
let mut t = pressed();
assert_eq!(t.deactivate(cx), vec![Action::Cancel], "a tool switch cancels the drag");
assert!(!t.busy() && !t.transforming());
assert!(t.pointer(cx, &PointerEvent::new(PointerKind::Up, q.x, q.y)).is_empty(), "the release commits nothing");
}
/// An 800 × 600 window on a view at 100% turned `deg` degrees clockwise (Rotate View): at 90°
/// one pixel right on screen is one point up the page.
pub fn turned_view(deg: f64) -> Option<ScreenFrame> {
+16
View File
@@ -184,4 +184,20 @@ mod tests {
spec.kind = RepeatKind::Mirror { angle: f64::NAN, center: Point::ZERO };
assert!(MirrorAxis::of(&doc, &selection, 1.0).is_none());
}
/// With the Selection tool, a drag of the axis reads where it is released, and a tool switch
/// cancels it.
#[test]
fn an_axis_drag_reads_its_release_and_a_tool_switch_cancels_it() {
let (mut doc, id) = doc_with_rect();
let mut source = doc.node(id).unwrap().clone();
source.id = doc.alloc_id();
doc.node_mut(id).unwrap().kind = NodeKind::Repeat(RepeatSpec::mirror(vec![Arc::new(source)], 90.0, 10.0));
let mut selection = Selection::default();
selection.set([id]);
let paint = paint();
let cx = cx(&doc, &selection, &paint);
let at = MirrorAxis::of(&doc, &selection, 1.0).unwrap().center;
crate::testutil::check_widget_release_and_tool_switch(&cx, at, at + Vec2::new(20.0, 0.0), at + Vec2::new(40.0, 0.0));
}
}
+9
View File
@@ -238,6 +238,15 @@ mod tests {
assert_eq!(t.pointer(&c, &ev(PointerKind::Up, 150.0, 250.0)), vec![Action::Commit]);
}
/// A guide drag reads where it is released, and a tool switch cancels it.
#[test]
fn a_guide_drag_reads_its_release_and_a_tool_switch_cancels_it() {
let d = editing(Some(SymbolNineSlice::default()));
let (s, p) = (Selection::default(), paint());
let c = cx(&d, &s, &p);
check_widget_release_and_tool_switch(&c, Point::new(126.0, 150.0), Point::new(115.0, 150.0), Point::new(105.0, 150.0));
}
/// Escape during a guide drag cancels it and is the tool's; the release after it commits
/// nothing. A double-click on a guide neither edits the art nor leaves the mode.
#[test]
+125 -7
View File
@@ -948,6 +948,9 @@ pub struct ObjectsOnPathTool {
member: Option<MemberDrag>,
/// Where the pointer is while no button is down, for the Select/Move widget it is over.
pointer: Option<Point>,
/// Where the pointer was at the last press or drag: a widget drag released anywhere else is
/// dragged there before it ends.
held_at: Option<Point>,
/// The reference point of each object attached next (0-8, row by row from the top left).
pivot: u8,
/// The angle of each object attached next, in degrees counter-clockwise from upright on the path.
@@ -956,7 +959,18 @@ pub struct ObjectsOnPathTool {
impl Default for ObjectsOnPathTool {
fn default() -> Self {
Self { hover: None, press: None, rotating: None, spacing: None, moving: None, member: None, pointer: None, pivot: CENTER, rotate: 0.0 }
Self {
hover: None,
press: None,
rotating: None,
spacing: None,
moving: None,
member: None,
pointer: None,
held_at: None,
pivot: CENTER,
rotate: 0.0,
}
}
}
@@ -967,31 +981,51 @@ impl Tool for ObjectsOnPathTool {
fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {
let p = ev.pos;
let released_away = ev.kind == PointerKind::Up && self.held_at != Some(p);
if matches!(ev.kind, PointerKind::Down | PointerKind::Drag) {
self.held_at = Some(p);
}
if let Some(d) = &mut self.rotating {
return match ev.kind {
PointerKind::Drag => d.drag(cx, p, ev.mods.shift),
PointerKind::Up => self.rotating.take().map(RotateAllDrag::finish).unwrap_or_default(),
PointerKind::Up => {
let mut out = if released_away { d.drag(cx, p, ev.mods.shift) } else { vec![] };
out.extend(self.rotating.take().map(RotateAllDrag::finish).unwrap_or_default());
out
}
_ => vec![],
};
}
if let Some(d) = &mut self.spacing {
return match ev.kind {
PointerKind::Drag => d.drag(cx, p, ev.mods.alt),
PointerKind::Up => self.spacing.take().map(SpaceDrag::finish).unwrap_or_default(),
PointerKind::Up => {
let mut out = if released_away { d.drag(cx, p, ev.mods.alt) } else { vec![] };
out.extend(self.spacing.take().map(SpaceDrag::finish).unwrap_or_default());
out
}
_ => vec![],
};
}
if let Some(d) = &mut self.moving {
return match ev.kind {
PointerKind::Drag => d.drag(cx, p),
PointerKind::Up => self.moving.take().map(MoveAllDrag::finish).unwrap_or_default(),
PointerKind::Up => {
let mut out = if released_away { d.drag(cx, p) } else { vec![] };
out.extend(self.moving.take().map(MoveAllDrag::finish).unwrap_or_default());
out
}
_ => vec![],
};
}
if let Some(d) = &mut self.member {
return match ev.kind {
PointerKind::Drag => d.drag(cx, p),
PointerKind::Up => self.member.take().map(MemberDrag::finish).unwrap_or_default(),
PointerKind::Up => {
let mut out = if released_away { d.drag(cx, p) } else { vec![] };
out.extend(self.member.take().map(MemberDrag::finish).unwrap_or_default());
out
}
_ => vec![],
};
}
@@ -1084,6 +1118,11 @@ impl Tool for ObjectsOnPathTool {
vec![]
}
/// Switching tools while the button is down cancels the click or the drag, as Escape does.
fn deactivate(&mut self, cx: &ToolContext) -> Vec<Action> {
self.key(cx, ToolKey::Escape, Mods::default())
}
fn options(&self) -> Value {
json!({ "pivot": self.pivot, "rotate": self.rotate })
}
@@ -1508,7 +1547,7 @@ mod tests {
assert!(matches!(a.last(), Some(Action::Preview(_, p)) if p["spacing"] == "auto" && p["start"] == 0.0), "{id}: {a:?}");
assert_eq!(spaced(&t.pointer(&c, &ev(PointerKind::Drag, at.x - 900.0, at.y))), Some((0.0, 0.0)), "{id}");
assert_eq!(spaced(&t.pointer(&c, &alt(PointerKind::Drag, at.x - 900.0, at.y))), Some((0.0, 200.0)), "{id}");
assert_eq!(t.pointer(&c, &ev(PointerKind::Up, at.x, at.y)), vec![Action::Commit], "{id}");
assert_eq!(t.pointer(&c, &alt(PointerKind::Up, at.x - 900.0, at.y)), vec![Action::Commit], "{id}");
assert!(!t.busy(), "{id}");
// A click on the widget that does not move changes nothing.
assert!(t.pointer(&c, &ev(PointerKind::Down, at.x, at.y)).is_empty());
@@ -1730,7 +1769,7 @@ mod tests {
assert_eq!(moved(&t.pointer(&c, &ev(PointerKind::Drag, at.x + 900.0, at.y))), Some((300.0, None)), "{id}");
assert_eq!(moved(&t.pointer(&c, &ev(PointerKind::Drag, at.x + 880.0, at.y))), Some((280.0, None)), "{id}");
assert_eq!(moved(&t.pointer(&c, &ev(PointerKind::Drag, at.x - 900.0, at.y))), Some((0.0, None)), "{id}");
assert_eq!(t.pointer(&c, &ev(PointerKind::Up, at.x, at.y)), vec![Action::Commit], "{id}");
assert_eq!(t.pointer(&c, &ev(PointerKind::Up, at.x - 900.0, at.y)), vec![Action::Commit], "{id}");
assert!(!t.busy(), "{id}");
// A click on the widget that does not move changes nothing.
assert!(t.pointer(&c, &ev(PointerKind::Down, at.x, at.y)).is_empty());
@@ -2007,6 +2046,85 @@ mod tests {
}
}
/// The release is read where it happens: a release away from the last drag event drags the
/// widget there before the drag ends, with the Selection tool and the Objects on Path tool.
#[test]
fn the_release_position_sets_each_widget() {
let new_tools = || -> [Box<dyn Tool>; 2] { [Box::new(crate::select::SelectionTool::default()), Box::new(ObjectsOnPathTool::default())] };
let paint = paint();
let (d, _, sel) = group_doc(0.0);
let c = cx(&d, &sel, &paint);
for mut t in new_tools() {
let (at, q, r) = (around(0.0), around(60.0), around(90.0));
t.pointer(&c, &ev(PointerKind::Down, at.x, at.y));
t.pointer(&c, &ev(PointerKind::Drag, q.x, q.y));
let a = t.pointer(&c, &ev(PointerKind::Up, r.x, r.y));
let (last, shown) = a.split_last().unwrap();
assert_eq!(last, &Action::Commit, "{}", t.id());
assert!(previewed(shown).is_some_and(|deg| (deg - 90.0).abs() < 1e-9), "{}: Rotate All {a:?}", t.id());
}
let at = SpaceWidget::of(&d, &sel, 1.0).unwrap().at;
for mut t in new_tools() {
t.pointer(&c, &ev(PointerKind::Down, at.x, at.y));
t.pointer(&c, &ev(PointerKind::Drag, at.x - 100.0, at.y));
let a = t.pointer(&c, &ev(PointerKind::Up, at.x - 50.0, at.y));
let (last, shown) = a.split_last().unwrap();
assert_eq!(last, &Action::Commit, "{}", t.id());
assert_eq!(spaced(shown), Some((350.0, 0.0)), "{}: Space {a:?}", t.id());
}
let (d, _, sel) = spaced_doc(Some(100.0), 50.0);
let c = cx(&d, &sel, &paint);
let at = MoveAllWidget::of(&d, &sel, 1.0).unwrap().at;
for mut t in new_tools() {
t.pointer(&c, &ev(PointerKind::Down, at.x, at.y));
t.pointer(&c, &ev(PointerKind::Drag, at.x + 80.0, at.y));
let a = t.pointer(&c, &ev(PointerKind::Up, at.x + 90.0, at.y));
let (last, shown) = a.split_last().unwrap();
assert_eq!(last, &Action::Commit, "{}", t.id());
assert_eq!(moved(shown), Some((140.0, None)), "{}: Move All {a:?}", t.id());
}
let (d, _, sel, ids) = three_doc();
let c = cx(&d, &sel, &paint);
for mut t in new_tools() {
t.pointer(&c, &ev(PointerKind::Down, 200.0, 300.0));
t.pointer(&c, &ev(PointerKind::Drag, 280.0, 310.0));
let a = t.pointer(&c, &ev(PointerKind::Up, 330.0, 300.0));
assert_eq!(previewed_target(&a), Some(ids[2].0), "{}: Select/Move {a:?}", t.id());
assert_eq!(a[1..], [Action::Commit, choose(ids[1])], "{}", t.id());
}
}
/// Switching tools during a widget drag cancels it, as Escape does, with the Selection tool and
/// the Objects on Path tool; after a press that has not moved there is nothing to put back.
#[test]
fn a_tool_switch_cancels_a_widget_drag() {
let new_tools = || -> [Box<dyn Tool>; 2] { [Box::new(crate::select::SelectionTool::default()), Box::new(ObjectsOnPathTool::default())] };
let paint = paint();
let (d, _, sel) = group_doc(0.0);
let (md, _, msel) = spaced_doc(Some(100.0), 50.0);
let (od, _, osel, _) = three_doc();
let space = SpaceWidget::of(&d, &sel, 1.0).unwrap().at;
let move_all = MoveAllWidget::of(&md, &msel, 1.0).unwrap().at;
let presses = [
(cx(&d, &sel, &paint), around(0.0), around(60.0)),
(cx(&d, &sel, &paint), space, space - Vec2::new(100.0, 0.0)),
(cx(&md, &msel, &paint), move_all, move_all + Vec2::new(80.0, 0.0)),
(cx(&od, &osel, &paint), Point::new(200.0, 300.0), Point::new(330.0, 300.0)),
];
for (c, at, q) in &presses {
for mut t in new_tools() {
t.pointer(c, &ev(PointerKind::Down, at.x, at.y));
assert!(!t.pointer(c, &ev(PointerKind::Drag, q.x, q.y)).is_empty(), "{}", t.id());
assert_eq!(t.deactivate(c), vec![Action::Cancel], "{} at {at:?}", t.id());
assert!(!t.busy() && !t.transforming(), "{}", t.id());
assert!(t.pointer(c, &ev(PointerKind::Up, q.x, q.y)).is_empty(), "{}: the release keeps nothing", t.id());
t.pointer(c, &ev(PointerKind::Down, at.x, at.y));
assert!(t.deactivate(c).is_empty(), "{}", t.id());
assert!(!t.busy(), "{}", t.id());
}
}
}
/// Round a closed path the drag goes on across the first anchor: the first object, dragged back
/// past it, takes the last place.
#[test]
+10
View File
@@ -305,6 +305,16 @@ mod tests {
assert!(t.pointer(&c, &ev(PointerKind::Up, Point::new(100.0, 200.0))).is_empty(), "the release commits nothing");
}
/// A pie widget drag with the Selection tool reads where it is released, and a tool switch
/// cancels it.
#[test]
fn a_pie_widget_drag_reads_its_release_and_a_tool_switch_cancels_it() {
let (d, _, s) = doc_with_ellipse((0.0, 360.0));
let p = paint();
let c = cx(&d, &s, &p);
check_widget_release_and_tool_switch(&c, Point::new(312.0, 150.0), Point::new(200.0, 20.0), Point::new(100.0, 150.0));
}
/// On a whole ellipse the two widgets sit at the very same point, whatever its size, place or
/// angle, so a press there always takes the End widget.
#[test]
+11
View File
@@ -369,6 +369,17 @@ mod tests {
assert!(GridDrag::hit(&c, g.rows_at, Mods { alt: true, ..Mods::default() }).is_none());
}
/// With the Selection tool, a handle drag reads where it is released, and a tool switch cancels
/// it.
#[test]
fn a_handle_drag_reads_its_release_and_a_tool_switch_cancels_it() {
let (doc, selection) = grid();
let paint = paint();
let c = cx(&doc, &selection, &paint);
let g = GridHandles::of(&doc, &selection, crate::select::selection_box(&c), 1.0).unwrap();
crate::testutil::check_widget_release_and_tool_switch(&c, g.rows_at, g.rows_at + Vec2::new(0.0, 240.0), g.rows_at + Vec2::new(0.0, 360.0));
}
#[test]
fn a_bounding_box_handle_wins_where_they_overlap() {
let (doc, selection) = grid();
+11
View File
@@ -533,6 +533,17 @@ mod tests {
assert!(RadialDrag::hit(&c, h.instances_at, Mods { alt: true, ..Mods::default() }).is_none());
}
/// With the Selection tool, a handle drag reads where it is released, and a tool switch cancels
/// it.
#[test]
fn a_handle_drag_reads_its_release_and_a_tool_switch_cancels_it() {
let (doc, selection) = radial();
let paint = paint();
let c = cx(&doc, &selection, &paint);
let at = RadialHandles::of(&doc, &selection, crate::select::selection_box(&c), 1.0).unwrap().instances_at;
crate::testutil::check_widget_release_and_tool_switch(&c, at, at + Vec2::new(0.0, 32.0), at + Vec2::new(0.0, 64.0));
}
#[test]
fn dragging_the_radius_handle_moves_the_circle_in_and_out() {
let (doc, selection) = radial();
+47 -15
View File
@@ -58,6 +58,14 @@ use crate::sidewidget::{self, SideDrag};
use crate::typewidget;
use crate::{Action, Cursor, Mods, Overlay, PixelOp, PointerEvent, PointerKind, Tool, ToolContext, ToolKey, json_ids};
/// The release of the widget drag `d`: released away from the last press or drag (`away`), it is
/// dragged there first (`drag`); then it ends (`finish`).
fn released<D>(mut d: D, away: bool, drag: impl FnOnce(&mut D) -> Vec<Action>, finish: impl FnOnce(D) -> Vec<Action>) -> Vec<Action> {
let mut out = if away { drag(&mut d) } else { vec![] };
out.extend(finish(d));
out
}
/// Direction is read on screen, even in a turned view. Within three pixels of the press's
/// horizontal position, retain the previous rule so hand jitter does not flip it.
fn marquee_direction(cx: &ToolContext, start: Point, cur: Point, previous: bool) -> bool {
@@ -199,6 +207,9 @@ pub struct SelectionTool {
loaded_at_press: Option<(NodeId, bool)>,
/// Where the pointer last hovered: the type on a path bracket under it draws thicker.
bracket_hover: Option<Point>,
/// Where the pointer was at the last press or drag: a widget drag released anywhere else is
/// dragged there before it ends.
held_at: Option<Point>,
}
/// What Distance Guides measure the selection to.
@@ -905,15 +916,32 @@ impl Tool for SelectionTool {
out
}
/// Switching tools during a drag of a blend widget, a corner widget, a pie widget or a
/// polygon's side widget cancels it, as Escape does: its value goes back.
/// Switching tools during a drag of a widget (a blend, corner, pie or side widget, an Objects on
/// Path widget, a bracket of type on a path, a repeat's control or a 9-slice guide) cancels it,
/// as Escape does: its value goes back.
fn deactivate(&mut self, _cx: &ToolContext) -> Vec<Action> {
match std::mem::take(&mut self.state) {
State::BlendWidget(d) if d.adjusting() => vec![Action::Cancel],
State::Corner(c) if c.adjusting() => vec![Action::Cancel],
State::Pie(d) if d.adjusting() => vec![Action::Cancel],
State::RotateAll(d) if d.adjusting() => vec![Action::Cancel],
State::Space(d) if d.adjusting() => vec![Action::Cancel],
State::MoveAll(d) if d.adjusting() => vec![Action::Cancel],
State::Member(d) if d.adjusting() => vec![Action::Cancel],
State::Bracket(b) if b.adjusting() => vec![Action::Cancel],
State::Sides(d) => d.cancel(),
State::BlendWidget(_) | State::Corner(_) | State::Pie(_) => vec![],
State::Mirror(d) => d.cancel(),
State::GridRepeat(d) => d.cancel(),
State::RadialRepeat(d) => d.cancel(),
State::NineSlice(d) => d.cancel(),
State::BlendWidget(_)
| State::Corner(_)
| State::Pie(_)
| State::RotateAll(_)
| State::Space(_)
| State::MoveAll(_)
| State::Member(_)
| State::Bracket(_) => vec![],
other => {
self.state = other;
vec![]
@@ -978,6 +1006,10 @@ impl Tool for SelectionTool {
/// the art; the drags then move, scale, rotate, marquee or drag what it took.
fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {
self.note_loaded_at_press(ev.kind);
let released_away = ev.kind == PointerKind::Up && self.held_at != Some(ev.pos);
if matches!(ev.kind, PointerKind::Down | PointerKind::Drag) {
self.held_at = Some(ev.pos);
}
let hovering = ev.kind == PointerKind::Move && matches!(self.state, State::Idle);
self.bracket_hover = hovering.then_some(ev.pos);
self.alt_hover = hovering && ev.mods.alt;
@@ -988,7 +1020,7 @@ impl Tool for SelectionTool {
return out;
}
// The edited symbol's 9-slice guides take precedence over every other control and the art.
if let Some(out) = self.nine_slice_guides(cx, ev) {
if let Some(out) = self.nine_slice_guides(cx, ev, released_away) {
return out;
}
// Mirror and grid repeat controls take precedence over art and ruler guides; the mirror
@@ -1129,7 +1161,7 @@ impl Tool for SelectionTool {
}
(PointerKind::Up, State::Corner(c)) => {
self.state = State::Idle;
c.finish()
released(c, released_away, |c| c.drag(cx, p), CornerDrag::finish)
}
(PointerKind::Drag, State::Pie(mut d)) => {
let out = d.drag(cx, p);
@@ -1138,7 +1170,7 @@ impl Tool for SelectionTool {
}
(PointerKind::Up, State::Pie(d)) => {
self.state = State::Idle;
d.finish()
released(d, released_away, |d| d.drag(cx, p), PieDrag::finish)
}
(PointerKind::Drag, State::Sides(mut d)) => {
let out = d.drag(cx, p);
@@ -1156,7 +1188,7 @@ impl Tool for SelectionTool {
}
(PointerKind::Up, State::BlendWidget(d)) => {
self.state = State::Idle;
d.finish()
released(d, released_away, |d| d.drag(cx, p), BlendWidgetDrag::finish)
}
(PointerKind::Drag, State::RotateAll(mut d)) => {
let out = d.drag(cx, p, m.shift);
@@ -1165,7 +1197,7 @@ impl Tool for SelectionTool {
}
(PointerKind::Up, State::RotateAll(d)) => {
self.state = State::Idle;
d.finish()
released(d, released_away, |d| d.drag(cx, p, m.shift), RotateAllDrag::finish)
}
(PointerKind::Drag, State::Space(mut d)) => {
let out = d.drag(cx, p, m.alt);
@@ -1174,7 +1206,7 @@ impl Tool for SelectionTool {
}
(PointerKind::Up, State::Space(d)) => {
self.state = State::Idle;
d.finish()
released(d, released_away, |d| d.drag(cx, p, m.alt), SpaceDrag::finish)
}
(PointerKind::Drag, State::MoveAll(mut d)) => {
let out = d.drag(cx, p);
@@ -1183,7 +1215,7 @@ impl Tool for SelectionTool {
}
(PointerKind::Up, State::MoveAll(d)) => {
self.state = State::Idle;
d.finish()
released(d, released_away, |d| d.drag(cx, p), MoveAllDrag::finish)
}
(PointerKind::Drag, State::Member(mut d)) => {
let out = d.drag(cx, p);
@@ -1192,7 +1224,7 @@ impl Tool for SelectionTool {
}
(PointerKind::Up, State::Member(d)) => {
self.state = State::Idle;
d.finish()
released(d, released_away, |d| d.drag(cx, p), MemberDrag::finish)
}
(PointerKind::Drag, State::Bracket(mut b)) => {
let out = b.drag(cx, p, m.cmd);
@@ -1201,7 +1233,7 @@ impl Tool for SelectionTool {
}
(PointerKind::Up, State::Bracket(b)) => {
self.state = State::Idle;
b.finish()
released(b, released_away, |b| b.drag(cx, p, m.cmd), BracketDrag::finish)
}
(PointerKind::Up, State::Moving { began, deselect, key, exclude, .. }) => {
self.release_move(cx, ev.backquote, began, deselect, key, exclude)
@@ -1589,8 +1621,8 @@ impl SelectionTool {
}
/// A press on a 9-slice guide of the edited symbol starts dragging it; the drag and the
/// release go to it.
fn nine_slice_guides(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Option<Vec<Action>> {
/// release go to it, and a release away from the last drag (`released_away`) moves it there.
fn nine_slice_guides(&mut self, cx: &ToolContext, ev: &PointerEvent, released_away: bool) -> Option<Vec<Action>> {
if let State::NineSlice(mut d) = self.state.clone() {
return Some(match ev.kind {
PointerKind::Drag => {
@@ -1600,7 +1632,7 @@ impl SelectionTool {
}
PointerKind::Up => {
self.state = State::Idle;
d.finish()
released(d, released_away, |d| d.drag(cx, ev.pos), crate::nineslice::GuideDrag::finish)
}
_ => vec![],
});
+22
View File
@@ -448,6 +448,28 @@ fn escape_cancels_a_bracket_drag() {
assert!(t.pointer(&cx, &ev(PointerKind::Up, 330.0, 290.0)).is_empty(), "the release commits nothing");
}
/// A bracket drag of type on a path reads where it is released, and a tool switch cancels it.
#[test]
fn a_bracket_drag_reads_its_release_and_a_tool_switch_cancels_it() {
let (d, id) = crate::testutil::doc_with_path_type();
let mut s = Selection::default();
s.add(id);
let p = paint();
let cx = cx(&d, &s, &p);
check_widget_release_and_tool_switch(&cx, Point::new(280.0, 290.0), Point::new(320.0, 290.0), Point::new(340.0, 290.0));
}
/// A corner widget drag reads where it is released, and a tool switch cancels it.
#[test]
fn a_corner_widget_drag_reads_its_release_and_a_tool_switch_cancels_it() {
let (d, id) = doc_with_live_rect();
let mut s = Selection::default();
s.add(id);
let p = paint();
let cx = cx(&d, &s, &p);
check_widget_release_and_tool_switch(&cx, Point::new(190.0, 191.0), Point::new(175.0, 176.0), Point::new(165.0, 166.0));
}
/// #812: with Smart Guides on, hovering near an object's centre or an anchor labels it, and a
/// press there grabs the object by that point.
#[test]