Quick Pen: a drag back to its start records no undo step

A drag on an anchor or a segment that is let go where it started now
moves nothing and adds no undo step. Before, it recorded a Move step
that changed nothing.
This commit is contained in:
dotCooCoo committed 2026-11-21 20:47:12 -08:00
1 parent ec18884308
commit 059628a14c
3 files changed
+21 -3

No files matched your search

+14
View File
@@ -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]
+3 -2
View File
@@ -505,9 +505,10 @@ impl QuickPenTool {
fn release_edit(&mut self, cx: &ToolContext, mut e: Edit, p: Point) -> Vec<Action> {
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;
}
+4 -1
View File
@@ -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<Arc<Node>>,
snap: Option<PointSnap>,
@@ -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
}