After Add in Change Parameters, the new-parameter row's expression goes back to the default a new row starts with. Fixes #1170.
This commit is contained in:
1 parent
2a4907884b
commit
9dc12b4d0f
2 files changed
+17
-1
No files matched your search
@@ -18,6 +18,8 @@ use crate::SolveApp;
|
|||||||
use crate::theme::Tokens;
|
use crate::theme::Tokens;
|
||||||
|
|
||||||
const UNITS: [&str; 9] = ["mm", "cm", "m", "in", "ft", "deg", "rad", "", "um"];
|
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).
|
/// Dialog state (what is being typed; the parameters themselves live in the document).
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -41,7 +43,7 @@ pub struct ParamsDialog {
|
|||||||
|
|
||||||
impl ParamsDialog {
|
impl ParamsDialog {
|
||||||
pub fn new() -> Self {
|
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).
|
/// The command the live preview should run (a valid expression being edited).
|
||||||
pub fn preview_commands(&self) -> Option<Vec<(String, Value)>> {
|
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) {
|
match app.run("parameters.add", p) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
d.new_name.clear();
|
d.new_name.clear();
|
||||||
|
d.new_expr = NEW_EXPR.into();
|
||||||
d.new_comment.clear();
|
d.new_comment.clear();
|
||||||
d.error = None;
|
d.error = None;
|
||||||
name.request_focus();
|
name.request_focus();
|
||||||
|
|||||||
@@ -124,3 +124,16 @@ fn parameter_rename_arrow_keys_move_cursor_and_keep_editing() {
|
|||||||
let result = h.app.session.execute("parameters.list", &json!({})).unwrap();
|
let result = h.app.session.execute("parameters.list", &json!({})).unwrap();
|
||||||
assert!(result["parameters"].as_array().unwrap().iter().any(|p| p["name"] == "plate_width"));
|
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);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user