fix(engine): Record Measurements labels a Count tool row "Count N" (#11775)

A row recorded from the Count tool was labelled "Measurement N" like a
selection row. It is now "Count N", as in the reference application,
with the same shared number; selection and ruler rows keep their labels
and every other column is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DuBearteandClaude Opus 5.5 committed 2026-11-07 02:04:30 -05:00
1 parent f68e227026
commit 39443ab3aa
3 files changed
+46 -1

No files matched your search

+2
View File
@@ -67,6 +67,8 @@ pub mod color_cmds;
pub mod color_to_alpha_cmds;
pub mod comps_cmds;
pub mod contour_lib_cmds;
#[cfg(test)]
mod count_record_label_tests;
pub mod cutout_cmds;
pub mod distort_cmds;
pub mod document_preset_cmds;
+3 -1
View File
@@ -1012,7 +1012,9 @@ fn record(s: &mut Session, p: &Value) -> Result<Value> {
other => return Err(bad(CMD, format!("unknown source `{other}` (auto|selection|ruler|count)"))),
};
// Numbered only once the rows exist, so a failed measurement does not use up a label.
let label = format!("Measurement {}", s.analysis.next_measurement + 1);
// A count's row is "Count N" (#11775); the number is the shared one.
let word = if source == "count" { "Count" } else { "Measurement" };
let label = format!("{word} {}", s.analysis.next_measurement + 1);
let now = p.get("dateTime").and_then(Value::as_str).map(str::to_string).unwrap_or_else(now_iso);
let factor = d.measurement.scale.factor();
let mut rows: Vec<Map<String, Value>> = Vec::new();
@@ -0,0 +1,41 @@
//! #11775: Record Measurements labels a Count tool row "Count N"; selection and ruler rows keep
//! their labels, and N is the number the row gets today (the shared counter).
use serde_json::{Value, json};
use crate::Session;
fn five_counts() -> Session {
let mut s = Session::new();
s.execute("file.new", json!({"width": 100, "height": 100})).unwrap();
for i in 0..5 {
s.execute("count.add", json!({"x": 10 + 10 * i, "y": 10})).unwrap();
}
s
}
fn record(s: &mut Session, source: &str) -> Value {
let r = s.execute("image.analysis.recordMeasurements", json!({"source": source})).unwrap();
r["rows"][0]["values"].clone()
}
#[test]
fn a_count_row_is_labelled_count_n() {
for source in ["count", "auto"] {
let mut s = five_counts();
let row = record(&mut s, source);
assert_eq!(row["label"], json!("Count 1"), "{source}: {row}");
assert_eq!(row["count"], json!(5), "{source}: {row}");
assert_eq!(row["source"], json!("Count Tool"), "{source}: {row}");
}
}
#[test]
fn other_rows_keep_their_labels_and_the_counter_is_shared() {
let mut s = five_counts();
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap();
let selection = record(&mut s, "selection");
assert!(selection["label"].as_str().is_some_and(|l| !l.starts_with("Count")), "{selection}");
let count = record(&mut s, "count");
assert_eq!(count["label"], json!("Count 2"), "{count}");
}