SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch: undo while drawing a spline removes the last point, not the sketch (#5304) (#5441)
raykholo745a24bbc85f
diff --git a/crates/ui-egui/src/sketch_shortcut_tests.rs b/crates/ui-egui/src/sketch_shortcut_tests.rsindex 9a330c99bf..f5bcdeb8f6 100644--- a/crates/ui-egui/src/sketch_shortcut_tests.rs+++ b/crates/ui-egui/src/sketch_shortcut_tests.rs@@ -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) indiff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rsindex c821a1aff5..7a8a7582d6 100644--- a/crates/ui-egui/src/toolbar.rs+++ b/crates/ui-egui/src/toolbar.rs@@ -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);diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rsindex 638232dc7f..d31f9f3c0e 100644--- a/crates/ui-egui/src/tools.rs+++ b/crates/ui-egui/src/tools.rs@@ -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();