Skip to content

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

Keep focus when correcting an invalid parameter name (#3965) (#4000)

taylorhayisff2ca2d46232
diff --git a/crates/ui-egui/src/params_dialog.rs b/crates/ui-egui/src/params_dialog.rs
index 4790ded689..e0fb32a4ab 100644
--- a/crates/ui-egui/src/params_dialog.rs
+++ b/crates/ui-egui/src/params_dialog.rs
@@ -687,7 +687,9 @@ fn add_row(app: &mut SolveApp, ui: &mut egui::Ui, table: &mut ui_kit::Table<'_>,
}
Err(error) => {
d.error = Some(error);
- if let Some(id) = focused_id {
+ // Enter stays in the field that was submitted. A click into another cell
+ // has to keep that cell, or an invalid name cannot be corrected (#3965).
+ if submit && let Some(id) = focused_id {
ui.memory_mut(|m| m.request_focus(id));
}
}
diff --git a/crates/ui-egui/tests/parameter_enter.rs b/crates/ui-egui/tests/parameter_enter.rs
index c842d3e9ff..fed8dfad2e 100644
--- a/crates/ui-egui/tests/parameter_enter.rs
+++ b/crates/ui-egui/tests/parameter_enter.rs
@@ -146,6 +146,29 @@ 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"));
}
+/// #3965: leaving an invalid name and clicking back into it must edit the name.
+/// Refusing the add used to put focus back on the field being left, so the
+/// correction was typed into the expression instead.
+#[test]
+fn invalid_parameter_name_stays_editable_after_leaving_it() {
+ let mut h = open();
+ fill(&mut h, "name", "bad name");
+ // A new row's expression starts blank. Type one, then leave it and come back to the name.
+ fill(&mut h, "expression", "10 mm");
+ h.run(&json!([
+ {"click":{"handle":"param:new:expression"}},
+ {"click":{"handle":"param:new:name"}},
+ {"key":"A","cmd":true},
+ {"text":"width"}
+ ]))
+ .unwrap();
+ let d = h.app.params.as_ref().unwrap();
+ assert_eq!(d.new_name, "width", "typing after returning to Name edits the name");
+ assert_eq!(d.new_expr, "10 mm", "the expression keeps the draft");
+ let result = h.app.session.execute("parameters.list", &json!({})).unwrap();
+ assert!(!result["parameters"].as_array().unwrap().iter().any(|p| p["name"] == "bad name" || p["name"] == "width"));
+}
+
#[test]
fn parameter_add_resets_expression_for_next_row() {
for (units, selected) in [("mm", 0), ("cm", 1), ("m", 2), ("in", 3), ("ft", 4)] {