From 80b90c5ebb913efbfbf9e5ab0d681d12195e40c3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 02:07:27 -0800 Subject: [PATCH] Quick Pen: a length drag out and back to the same length records no undo step A length drag that changed the length and then came back to where it started previewed the path again at its first length, so letting go recorded an undo step for an unchanged path. A drag that ends at the length the piece started with is now taken back as Escape takes it back, on the path being drawn and on a selected path. --- crates/engine/src/tests/quickpen.rs | 23 ++++++++++++++--------- crates/tools/src/quickpen.rs | 12 ++++++++---- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index 443a0db7cd..dc660e919b 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -1084,8 +1084,8 @@ fn a_length_drag_stays_on_the_canvas() { assert_eq!(only_path(&s).anchors.len(), 3, "the drawing went on"); } -/// A length drag across a line, which leaves its length as it was, changes nothing and records no -/// undo step, on the path being drawn and on a selected path. +/// A length drag across a line, or out along it and back, leaves its length as it was: it changes +/// nothing and records no undo step, on the path being drawn and on a selected path. #[test] fn a_length_drag_that_keeps_the_length_records_no_undo_step() { let mut s = session(); @@ -1094,15 +1094,20 @@ fn a_length_drag_that_keeps_the_length_records_no_undo_step() { click(&mut s, 200.0, 100.0); let undo = undo_steps(&s); let before = only_path(&s); - // The end handle is at (220, 100); the drag goes straight down from it. - press(&mut s, &[(220.0, 100.0), (220.0, 160.0)]); - assert_eq!(only_path(&s), before); - assert_eq!(undo_steps(&s), undo); + // The end handle is at (220, 100); the first drag goes straight down from it, the second out + // along the line and back. + for drag in [[(220.0, 100.0), (220.0, 160.0), (220.0, 160.0)], [(220.0, 100.0), (260.0, 100.0), (220.0, 100.0)]] { + press(&mut s, &drag); + assert_eq!(only_path(&s), before, "{drag:?}"); + assert_eq!(undo_steps(&s), undo, "{drag:?}"); + } key(&mut s, ToolKey::Escape); let undo = undo_steps(&s); - press(&mut s, &[(220.0, 100.0), (220.0, 160.0)]); - assert_eq!(only_path(&s), before); - assert_eq!(undo_steps(&s), undo); + for drag in [[(220.0, 100.0), (220.0, 160.0), (220.0, 160.0)], [(220.0, 100.0), (260.0, 100.0), (220.0, 100.0)]] { + press(&mut s, &drag); + assert_eq!(only_path(&s), before, "{drag:?}"); + assert_eq!(undo_steps(&s), undo, "{drag:?}"); + } } /// The paths of a selected compound path show length handles, also after a drag selected the diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index b00524643a..23d19bc87e 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -941,11 +941,15 @@ impl QuickPenTool { if !drag.begun { return vec![]; } - // The command leaves a piece that already has the length unchanged; a drag that drew the - // last piece again has already changed the drawing. + // A drag that ends at the length the piece started with is taken back, as Escape takes it + // back: it records no undo step. let changed = (drag.length - drag.handle.piece.length).abs() > 1e-9 * drag.length.max(1.0); - if changed - && drag.last.is_none() + if !changed { + self.restore_last_piece(&drag); + return vec![Action::Cancel, drawn()]; + } + // A drag that drew the last piece again has already changed the drawing. + if drag.last.is_none() && let Some(dr) = self.drawing.as_mut() && dr.id == Some(drag.handle.id) && dr.si == drag.handle.si