Repeat: switching tools during a mirror axis or repeat handle drag puts it back

Switching away from the Selection tool while dragging a mirror axis or a
grid or radial repeat's handles left the drag's preview open under the
next tool. The Selection tool now cancels these drags on a tool switch,
as Escape already did, so the repeat goes back to its options from
before the press. A press that has not changed anything leaves no undo
step.

The deactivate doc comment now lists these drags and the Image Trace
divider.
This commit is contained in:
dotCooCoo
2026-11-18 16:54:56 -08:00
parent 61cc30e9b8
commit b92cdba3e0
4 changed files with 73 additions and 2 deletions
+25
View File
@@ -184,4 +184,29 @@ mod tests {
spec.kind = RepeatKind::Mirror { angle: f64::NAN, center: Point::ZERO };
assert!(MirrorAxis::of(&doc, &selection, 1.0).is_none());
}
#[test]
fn a_tool_switch_cancels_a_mirror_axis_drag() {
use crate::{PointerEvent, PointerKind, Tool};
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 c = cx(&doc, &selection, &paint);
let axis = MirrorAxis::of(&doc, &selection, c.zoom).unwrap();
let mut t = crate::select::SelectionTool::default();
assert!(t.pointer(&c, &PointerEvent::new(PointerKind::Down, axis.center.x, axis.center.y)).is_empty());
let a = t.pointer(&c, &PointerEvent::new(PointerKind::Drag, axis.center.x + 20.0, axis.center.y));
assert!(matches!(a.first(), Some(Action::Begin(l)) if l == "Repeat Options"), "{a:?}");
assert_eq!(t.deactivate(&c), vec![Action::Cancel]);
assert!(!t.busy());
// A press that has not moved the axis leaves nothing to cancel.
t.pointer(&c, &PointerEvent::new(PointerKind::Down, axis.center.x, axis.center.y));
assert!(t.busy());
assert!(t.deactivate(&c).is_empty());
assert!(!t.busy());
}
}
+20
View File
@@ -392,4 +392,24 @@ mod tests {
assert_eq!(cursor(&c, g.rows_at), Some(Cursor::ResizeV));
assert_eq!(cursor(&c, g.corner_at), Some(Cursor::ResizeNwSe));
}
#[test]
fn a_tool_switch_cancels_a_grid_handle_drag() {
use crate::{PointerEvent, PointerKind, Tool};
let (doc, selection) = grid();
let paint = paint();
let c = cx(&doc, &selection, &paint);
let g = GridHandles::of(&doc, &selection, crate::select::selection_box(&c), c.zoom).unwrap();
let mut t = crate::select::SelectionTool::default();
assert!(t.pointer(&c, &PointerEvent::new(PointerKind::Down, g.rows_at.x, g.rows_at.y)).is_empty());
let a = t.pointer(&c, &PointerEvent::new(PointerKind::Drag, g.rows_at.x, g.rows_at.y + 150.0));
assert!(preview(&a).is_some(), "{a:?}");
assert_eq!(t.deactivate(&c), vec![Action::Cancel]);
assert!(!t.busy());
// A press that has not changed the grid leaves nothing to cancel.
t.pointer(&c, &PointerEvent::new(PointerKind::Down, g.rows_at.x, g.rows_at.y));
assert!(t.busy());
assert!(t.deactivate(&c).is_empty());
assert!(!t.busy());
}
}
+22
View File
@@ -681,4 +681,26 @@ mod tests {
assert_eq!(preview(&d.drag(h.instances_at + Vec2::new(0.0, 32.0))), Some(&json!({"instances": 9})));
assert!(matches!(d.finish().as_slice(), [Action::Commit]));
}
#[test]
fn a_tool_switch_cancels_a_radial_handle_drag() {
use crate::{PointerEvent, PointerKind, Tool};
let (doc, selection) = radial();
let paint = paint();
let c = cx(&doc, &selection, &paint);
let h = RadialHandles::of(&doc, &selection, crate::select::selection_box(&c), c.zoom).unwrap();
let out = (h.radius_at - h.center) / 100.0;
let to = h.radius_at + out * 25.0;
let mut t = crate::select::SelectionTool::default();
assert!(t.pointer(&c, &PointerEvent::new(PointerKind::Down, h.radius_at.x, h.radius_at.y)).is_empty());
let a = t.pointer(&c, &PointerEvent::new(PointerKind::Drag, to.x, to.y));
assert_eq!(preview(&a), Some(&json!({"radius": 125.0})), "{a:?}");
assert_eq!(t.deactivate(&c), vec![Action::Cancel]);
assert!(!t.busy());
// A press that has not changed the repeat leaves nothing to cancel.
t.pointer(&c, &PointerEvent::new(PointerKind::Down, h.radius_at.x, h.radius_at.y));
assert!(t.busy());
assert!(t.deactivate(&c).is_empty());
assert!(!t.busy());
}
}
+6 -2
View File
@@ -907,14 +907,18 @@ 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 blend widget, a corner widget, a pie widget, a
/// polygon's side widget, a mirror axis, a grid or radial repeat's handles or an Image Trace
/// divider 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::Sides(d) => d.cancel(),
State::Mirror(d) => d.cancel(),
State::GridRepeat(d) => d.cancel(),
State::RadialRepeat(d) => d.cancel(),
State::TraceSplit(d) => d.cancel(),
State::BlendWidget(_) | State::Corner(_) | State::Pie(_) => vec![],
other => {