mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 11:51:05 +01:00
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.
This commit is contained in:
1 parent
d1eb3f4ad3
commit
80b90c5ebb
2 files changed
+22
-13
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user