Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Parameters: reset the new row's expression after Add (#1170) (#1235)

DuBearte9dc12b4d0f5c
diff --git a/crates/ui-egui/src/params_dialog.rs b/crates/ui-egui/src/params_dialog.rs
index 2f2f030ea8..408304c3a5 100644
--- a/crates/ui-egui/src/params_dialog.rs
+++ b/crates/ui-egui/src/params_dialog.rs
@@ -18,6 +18,8 @@ use crate::SolveApp;
use crate::theme::Tokens;
const UNITS: [&str; 9] = ["mm", "cm", "m", "in", "ft", "deg", "rad", "", "um"];
+/// The expression a new parameter row starts with.
+const NEW_EXPR: &str = "10 mm";
/// Dialog state (what is being typed; the parameters themselves live in the document).
#[derive(Default)]
@@ -41,7 +43,7 @@ pub struct ParamsDialog {
impl ParamsDialog {
pub fn new() -> Self {
- ParamsDialog { new_expr: "10 mm".into(), ..Default::default() }
+ ParamsDialog { new_expr: NEW_EXPR.into(), ..Default::default() }
}
/// The command the live preview should run (a valid expression being edited).
pub fn preview_commands(&self) -> Option<Vec<(String, Value)>> {
@@ -408,6 +410,7 @@ fn add_row(app: &mut SolveApp, ui: &mut egui::Ui, d: &mut ParamsDialog) {
match app.run("parameters.add", p) {
Ok(_) => {
d.new_name.clear();
+ d.new_expr = NEW_EXPR.into();
d.new_comment.clear();
d.error = None;
name.request_focus();
diff --git a/crates/ui-egui/tests/parameter_enter.rs b/crates/ui-egui/tests/parameter_enter.rs
index 92fe227f9c..87f68f0972 100644
--- a/crates/ui-egui/tests/parameter_enter.rs
+++ b/crates/ui-egui/tests/parameter_enter.rs
@@ -124,3 +124,16 @@ fn parameter_rename_arrow_keys_move_cursor_and_keep_editing() {
let result = h.app.session.execute("parameters.list", &json!({})).unwrap();
assert!(result["parameters"].as_array().unwrap().iter().any(|p| p["name"] == "plate_width"));
}
+#[test]
+fn parameter_add_resets_expression_for_next_row() {
+ let mut h = open();
+ let initial = h.app.params.as_ref().unwrap().new_expr.clone();
+ fill(&mut h, "name", "width");
+ fill(&mut h, "expression", "25 mm");
+ enter(&mut h, false);
+ let result = h.app.session.execute("parameters.list", &json!({})).unwrap();
+ assert!(result["parameters"].as_array().unwrap().iter().any(|p| p["name"] == "width" && p["expression"] == "25 mm"));
+ let d = h.app.params.as_ref().unwrap();
+ assert!(d.new_name.is_empty());
+ assert_eq!(d.new_expr, initial);
+}