Sketch: undo while drawing a spline removes the last point, not the sketch (#5304) (#5441)

* claim: #5304

* Sketch: undo and Backspace remove the last pending spline point (#5304)

While a spline tool has points placed, Cmd/Ctrl+Z and Backspace take back
the last point instead of undoing sketch history or deleting the selection.
Undo reaches sketch history again once no spline points remain.
This commit is contained in:
raykholo authored and GitHub committed 2026-10-25 01:26:15 +00:00
1 parent 26340882c0
commit 745a24bbc8
3 files changed
+70 -1

No files matched your search

@@ -17,6 +17,59 @@ fn press(h: &mut Harness, key: &str) {
h.settle();
}
#[test]
fn spline_undo_removes_pending_points_before_sketch_history() {
for cmd in ["sketch.spline.fit_point", "sketch.spline.control_point", "sketch.spline.control_point_5"] {
let mut h = Harness::new();
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0":[-20,-20],"p1":[-10,-10]})).unwrap();
h.settle();
h.step(&json!({"start":cmd})).unwrap();
for point in [[2, 2, 0], [8, 2, 0], [9, 7, 0]] {
h.step(&json!({"click":{"world":point}})).unwrap();
}
let points = h.app.tool.as_ref().unwrap().pts.clone();
assert_eq!(points.len(), 3);
let before = (h.app.session.doc.to_json(), h.app.session.undo.len(), h.app.session.revision);
for remaining in (0..3).rev() {
h.step(&json!({"key":"Z","cmd":true})).unwrap();
h.settle();
assert_eq!(h.app.tool.as_ref().unwrap().pts, points[..remaining], "{cmd}");
assert_eq!((h.app.session.doc.to_json(), h.app.session.undo.len(), h.app.session.revision), before, "{cmd}");
}
assert_eq!(tool(&h), Some(cmd));
h.step(&json!({"key":"Z","cmd":true})).unwrap();
h.settle();
assert_eq!(h.app.session.undo.len(), before.1 - 1, "history resumes once the spline is empty");
let sketch = h.app.session.active_sketch.unwrap();
assert!(h.app.session.model.state().sketch(sketch).unwrap().sketch.curves.is_empty());
}
}
#[test]
fn spline_backspace_removes_pending_points_and_keeps_the_tool_ready() {
let mut h = Harness::new();
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0":[-20,-20],"p1":[-10,-10]})).unwrap();
h.settle();
h.step(&json!({"start":"sketch.spline.fit_point"})).unwrap();
for point in [[2, 2, 0], [8, 2, 0], [9, 7, 0]] {
h.step(&json!({"click":{"world":point}})).unwrap();
}
let points = h.app.tool.as_ref().unwrap().pts.clone();
assert_eq!(points.len(), 3);
let before = (h.app.session.doc.to_json(), h.app.session.undo.len(), h.app.session.revision);
for remaining in (0..3).rev() {
press(&mut h, "Backspace");
assert_eq!(h.app.tool.as_ref().unwrap().pts, points[..remaining]);
assert_eq!((h.app.session.doc.to_json(), h.app.session.undo.len(), h.app.session.revision), before);
}
assert_eq!(tool(&h), Some("sketch.spline.fit_point"));
press(&mut h, "Escape");
assert!(tool(&h).is_none());
assert_eq!((h.app.session.doc.to_json(), h.app.session.undo.len(), h.app.session.revision), before);
}
#[test]
fn sketch_keys_outside_a_sketch_sketch_on_the_selected_plane_and_start_their_tool() {
for (key, cmd) in
+6 -1
View File
@@ -2029,7 +2029,11 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
});
}
_ if !shown => {}
Key::Z => drop(app.run("edit.undo", json!({}))),
Key::Z => {
if !crate::tools::undo_spline_point(app) {
drop(app.run("edit.undo", json!({})));
}
}
Key::Y => drop(app.run("edit.redo", json!({}))),
// Copy, Cut and Paste (`edit_clipboard::handle`).
Key::C | Key::X | Key::V if !mods.shift && !mods.alt => {}
@@ -2101,6 +2105,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
crate::context_menu::rename_selection(app, at);
}
Key::F6 => app.animate_view("fit"),
Key::Backspace if crate::tools::undo_spline_point(app) => {}
Key::Delete | Key::Backspace => {
if !crate::timeline_left::delete_selected_folders(app) {
crate::viewport::delete_selection(app);
+11
View File
@@ -652,6 +652,17 @@ fn run_pick(app: &mut SolveApp, t: &Tool) {
let _ = app.run(t.cmd, params);
}
/// Take back a pending spline point before undo or Backspace reaches the sketch.
pub fn undo_spline_point(app: &mut SolveApp) -> bool {
let Some(t) = app.tool.as_mut() else { return false };
if !matches!(t.cmd, "sketch.spline.fit_point" | "sketch.spline.control_point" | "sketch.spline.control_point_5") || t.pts.is_empty() {
return false;
}
t.pts.pop();
crate::sketch_dims::reset(t);
true
}
/// Right click / Esc: end the current chain (line) or cancel the tool.
pub fn finish(app: &mut SolveApp) {
crate::dim_view::cancel();