From 707ce9e14cb85f34ead23b3d43ad556be58c56bc Mon Sep 17 00:00:00 2001 From: Harrison Booth <73434116+Harrison-Booth@users.noreply.github.com> Date: Sat, 24 Oct 2026 17:26:54 -0500 Subject: [PATCH] Resize Table: name formula headers by value and clear pictures under normalized headers A formula header with formulas shown was named by its source text, so the header became constant text like "=1+1". Use the value text instead. Header normalization wrote through cells.set, which left a picture at that address in place. Use Sheet::set_cell so the picture is removed with it. --- crates/engine/src/cmd/extra.rs | 4 +-- .../engine/tests/it/table_resize_overlap.rs | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/extra.rs b/crates/engine/src/cmd/extra.rs index ccdf087704..6a4551210e 100644 --- a/crates/engine/src/cmd/extra.rs +++ b/crates/engine/src/cmd/extra.rs @@ -889,7 +889,7 @@ fn table_resize(s: &mut Session, p: &Json) -> Result { let v = sheet.value(at); let text = match v.as_text() { Some(x) => x.to_string(), - None => crate::display::cell_text(wb, sheet, at), + None => crate::display::value_text(wb, sheet, at), }; (!text.trim().is_empty()).then_some(text) }) @@ -930,7 +930,7 @@ fn table_resize(s: &mut Session, p: &Json) -> Result { let constant_text = sheet.value(at).as_text() == Some(col.name.as_str()) && sheet.cell(at).is_some_and(|x| x.formula.is_none()); if !constant_text { let style = sheet.style_id(at); - sheet.cells.set(at, Cell { value: Value::text(col.name.as_str()), style, ..Default::default() }); + sheet.set_cell(at, Cell { value: Value::text(col.name.as_str()), style, ..Default::default() }); } } } diff --git a/crates/engine/tests/it/table_resize_overlap.rs b/crates/engine/tests/it/table_resize_overlap.rs index a80282aa46..7bdae2ebbc 100644 --- a/crates/engine/tests/it/table_resize_overlap.rs +++ b/crates/engine/tests/it/table_resize_overlap.rs @@ -193,3 +193,29 @@ fn resizing_a_table_without_a_header_row_keeps_its_names_and_data() { assert_eq!(names(&s, 0), ["a", "b", "Column1"]); assert_eq!(sheet(&s).value(r.start).display(), first); } + +#[test] +fn resized_formula_header_is_named_by_its_value_when_formulas_show() { + let mut s = with_headers("A1:B3", &["x", "y"]); + s.execute("cell.set", json!({"cell": "C1", "input": "=1+1"})).unwrap(); + { + let wb = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().wb); + std::sync::Arc::make_mut(&mut wb.sheets[0]).show_formulas = true; + } + s.execute("table.resize", json!({"table": "T", "range": "A1:C3"})).unwrap(); + assert_eq!(names(&s, 0), ["x", "y", "2"]); + assert_eq!(headers(&s, 0), names(&s, 0)); +} + +#[test] +fn resized_picture_header_is_replaced_and_its_picture_removed() { + let mut s = with_headers("A1:B3", &["x", "y"]); + { + let wb = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().wb); + let picture = gridcraft_engine::model::CellPicture { data: vec![1, 2, 3], mime: "image/png".into(), alt: String::new() }; + std::sync::Arc::make_mut(&mut wb.sheets[0]).set_picture(gridcraft_core::CellRef::new(0, 2), std::sync::Arc::new(picture)); + } + s.execute("table.resize", json!({"table": "T", "range": "A1:C3"})).unwrap(); + assert!(!sheet(&s).cell_pictures.contains_key(&gridcraft_core::CellRef::new(0, 2))); + assert_eq!(headers(&s, 0), names(&s, 0)); +}