diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index 412406c80a..b1142eff1f 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -664,6 +664,20 @@ fn a_release_past_the_drag_distance_moves_the_anchor() { assert_eq!(paths(&s).len(), 1, "no new path"); } +/// A drag on an anchor or a segment that comes back to where it started moves nothing and records +/// no undo step. +#[test] +fn a_drag_back_to_its_start_records_no_undo_step() { + let mut s = session(); + selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}])); + let undo = undo_steps(&s); + for at in [(200.0, 100.0), (250.0, 100.0)] { + press(&mut s, &[at, (at.0, at.1 + 50.0), at]); + assert_eq!(points(&s), [pt(100.0, 100.0), pt(200.0, 100.0), pt(300.0, 100.0)], "press at {at:?}"); + assert_eq!(undo_steps(&s), undo, "press at {at:?}"); + } +} + /// When another command edits the path while the press is down, neither a drag nor a release past /// the drag distance moves the anchor the press found. #[test] diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index c3188250fb..106f320e49 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -505,9 +505,10 @@ impl QuickPenTool { fn release_edit(&mut self, cx: &ToolContext, mut e: Edit, p: Point) -> Vec { if e.began || p.distance(e.start) >= cx.tol(DRAG_PX) { let mut out = e.drag(cx, p); - // A drag that could not begin (its path changed under the press) has no step to end. + // A drag that could not begin (its path changed under the press) has no step to end, + // and one that came back to where it started records none. if e.began { - out.push(Action::Commit); + out.push(if e.moved { Action::Commit } else { Action::Cancel }); } return out; } diff --git a/crates/tools/src/quickpen/edit.rs b/crates/tools/src/quickpen/edit.rs index a7d5f6de55..be23386268 100644 --- a/crates/tools/src/quickpen/edit.rs +++ b/crates/tools/src/quickpen/edit.rs @@ -81,6 +81,8 @@ pub(super) struct Edit { pub(super) shift: bool, /// Whether the press has dragged far enough to move what it holds (an undo step began). pub(super) began: bool, + /// Whether the last drag left what the press holds away from where it started. + pub(super) moved: bool, /// The grabbed path as the document had it when the press went down. pressed: Option>, snap: Option, @@ -90,7 +92,7 @@ pub(super) struct Edit { impl Edit { pub(super) fn new(cx: &ToolContext, grab: Grab, start: Point, shift: bool) -> Self { let pressed = shared_node(cx.doc, grab.id()).cloned(); - Self { grab, start, shift, began: false, pressed, snap: None, guides: vec![] } + Self { grab, start, shift, began: false, moved: false, pressed, snap: None, guides: vec![] } } /// Whether the grabbed path is as the document had it when the press went down. @@ -154,6 +156,7 @@ impl Edit { if !d.x.is_finite() || !d.y.is_finite() { return out; } + self.moved = d.x != 0.0 || d.y != 0.0; out.push(Action::Preview("path.moveAnchors".into(), json!({"dx": d.x, "dy": d.y, "interpolate": true}))); out }