From a2f63044c976b7022d373f42d44c4db0bc4d1582 Mon Sep 17 00:00:00 2001 From: KrataPremium <155114492+kratagit@users.noreply.github.com> Date: Sat, 28 Nov 2026 22:12:11 +0100 Subject: [PATCH] fix(analysis): name measurement scale history steps after the submenu entry Custom (dialog, preset, script set) adds "Custom Measurement Scale" and Default adds "Set Default Measurement Scale", as the reference application does; an unchanged scale still adds no step. Fixes #17410. --- crates/engine-core/src/cmd/analysis_cmds.rs | 6 +- .../scale_history_names_tests.rs | 60 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 crates/engine-core/src/cmd/analysis_cmds/scale_history_names_tests.rs diff --git a/crates/engine-core/src/cmd/analysis_cmds.rs b/crates/engine-core/src/cmd/analysis_cmds.rs index 5e6de123bd..401737c6fb 100644 --- a/crates/engine-core/src/cmd/analysis_cmds.rs +++ b/crates/engine-core/src/cmd/analysis_cmds.rs @@ -296,8 +296,10 @@ fn set_scale(s: &mut Session, p: &Value) -> Result { other => return Err(bad(CMD, format!("unknown preset `{other}` (default|custom)"))), }; if next != cur { + // The reference names the step after the submenu entry that made it (#17410). + let label = if preset == "default" { "Set Default Measurement Scale" } else { "Custom Measurement Scale" }; let n = next.clone(); - s.edit("Set Measurement Scale", move |d, _| { + s.edit(label, move |d, _| { d.measurement.scale = n; Ok(()) })?; @@ -1409,4 +1411,6 @@ mod analysis_straighten_enabled_tests; #[path = "analysis_straighten_selection_tests.rs"] mod analysis_straighten_selection_tests; #[cfg(test)] +mod scale_history_names_tests; +#[cfg(test)] mod tests; diff --git a/crates/engine-core/src/cmd/analysis_cmds/scale_history_names_tests.rs b/crates/engine-core/src/cmd/analysis_cmds/scale_history_names_tests.rs new file mode 100644 index 0000000000..de5298f1b3 --- /dev/null +++ b/crates/engine-core/src/cmd/analysis_cmds/scale_history_names_tests.rs @@ -0,0 +1,60 @@ +//! History step names of Image › Analysis › Set Measurement Scale, measured against the reference +//! application (#17410): Custom (the dialog, a preset, a script set) adds one step "Custom +//! Measurement Scale", Default adds one step "Set Default Measurement Scale", and a call that +//! leaves the scale as it is adds no step. + +use super::*; + +const CMD: &str = "image.analysis.setMeasurementScale"; + +fn session() -> Session { + let mut s = crate::session(); + s.execute("file.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap(); + s +} + +fn steps(s: &Session) -> usize { + s.active().unwrap().history.past_len() +} + +fn last_step(s: &Session) -> String { + s.active().unwrap().history.entries().last().cloned().unwrap_or_default() +} + +#[test] +fn custom_and_bare_values_add_one_custom_step() { + for p in [ + json!({"preset": "custom", "pixelLength": 100, "logicalLength": 2.5, "units": "cm"}), + json!({"pixelLength": 100, "logicalLength": 2.5, "units": "cm"}), + json!({"units": "mm"}), + ] { + let mut s = session(); + let before = steps(&s); + s.execute(CMD, p.clone()).unwrap(); + assert_eq!(steps(&s), before + 1, "{p}"); + assert_eq!(last_step(&s), "Custom Measurement Scale", "{p}"); + } +} + +#[test] +fn default_adds_one_default_step() { + let mut s = session(); + s.execute(CMD, json!({"pixelLength": 10, "logicalLength": 1, "units": "cm"})).unwrap(); + let before = steps(&s); + s.execute(CMD, json!({"preset": "default"})).unwrap(); + assert_eq!(steps(&s), before + 1); + assert_eq!(last_step(&s), "Set Default Measurement Scale"); +} + +#[test] +fn unchanged_scale_adds_no_step() { + let mut s = session(); + let before = steps(&s); + s.execute(CMD, json!({"preset": "default"})).unwrap(); + assert_eq!(steps(&s), before, "Default on a default scale"); + let p = json!({"pixelLength": 10, "logicalLength": 1, "units": "cm"}); + s.execute(CMD, p.clone()).unwrap(); + let before = steps(&s); + s.execute(CMD, p).unwrap(); + assert_eq!(steps(&s), before, "the same custom values again"); +}