* claim: #3965 * Parameters: a click can correct an invalid name (#3965) Refusing the new row was putting focus back on the field being left, so the correction was typed into the expression. * Parameters: the invalid-name test types its expression draft (#3965) A new row starts with a blank expression, so the regression test types 10 mm and checks that correcting the name leaves that draft in place.
This commit is contained in:
1 parent
ab80a410a1
commit
ff2ca2d462
2 files changed
+26
-1
No files matched your search
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)] {
|
||||
|
||||
Reference in new issue
Block a user