diff --git a/crates/engine/src/cmd/table.rs b/crates/engine/src/cmd/table.rs index c6f2be0f7..f8a13723b 100644 --- a/crates/engine/src/cmd/table.rs +++ b/crates/engine/src/cmd/table.rs @@ -360,7 +360,18 @@ fn insert_col_like(t: &mut Table, at: usize, neighbour: usize, keep_width: bool) let total = t.width(); let neighbour = neighbour.min(t.cols.len().saturating_sub(1)); let w = t.cols.get(neighbour).copied(); - let templates: Vec> = t.rows.iter().map(|r| r.cells.get(neighbour).cloned()).collect(); + // A neighbour covered by a horizontal merge is formatted as its anchor, which is what shows. + let templates: Vec> = t + .rows + .iter() + .map(|r| { + let mut n = neighbour; + while n > 0 && r.cells.get(n).is_some_and(|c| c.h_merge) { + n -= 1; + } + r.cells.get(n).cloned() + }) + .collect(); t.insert_col(at); let at = at.min(t.cols.len().saturating_sub(1)); if let (Some(w), Some(slot)) = (w, t.cols.get_mut(at)) { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 96669cb01..c3e419e0a 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -6557,6 +6557,20 @@ fn table_insert_column_with_keep_width_keeps_the_table_width_and_copies_the_neig assert!((x.w - 840.0).abs() < 1e-6, "frame {}", x.w); } +#[test] +fn table_insert_column_beside_a_merge_copies_the_anchor_format() { + let mut s = session(); + let id = table_at(&mut s, &[280.0, 280.0, 280.0], json!([["a", "b", "c"], ["d", "e", "f"]])); + s.execute("table.cellFill", &json!({"id": id.0, "color": "#FF0000", "cells": [[0, 0]]})).unwrap(); + s.execute("table.merge", &json!({"id": id.0, "from": [0, 0], "to": [0, 1]})).unwrap(); + // Right of the merge: the neighbour column holds the covered cell, but the anchor shows. + s.execute("table.insertColumnRight", &json!({"id": id.0, "col": 1})).unwrap(); + let t = table_of(&s, id); + assert!(t.cell(0, 1).unwrap().h_merge, "the merge stays put"); + assert_eq!(t.cell(0, 2).unwrap().fill, t.cell(0, 0).unwrap().fill); + assert!(t.cell(0, 2).unwrap().fill.is_some()); +} + /// A table near the slide's right edge, with no room for another column: by default an inserted /// column widens it past the edge, as PowerPoint's Insert Right does (the frame keeps its left and /// grows), and `keepWidth: true` keeps it on the slide.