Insert column: resolve a covered neighbour to its anchor vertically too

A neighbour cell inside a multi-row merge sits below the anchor and carries the
vertical cover flag, so the new column's cell copied an unformatted cell. Walk
up and left to the visible anchor; the test merges two rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zach Berry
2026-11-04 22:33:17 -06:00
co-authored by Claude Opus 5.5
parent f0c202dca8
commit c86eee0355
2 changed files with 28 additions and 9 deletions
+15 -9
View File
@@ -360,16 +360,22 @@ 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();
// A neighbour covered by a horizontal merge is formatted as its anchor, which is what shows.
let templates: Vec<Option<Cell>> = 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;
// A neighbour covered by a merge (horizontally or vertically) is formatted as its anchor, which is what shows.
let covered = |r: usize, c: usize| t.rows.get(r).and_then(|row| row.cells.get(c)).is_some_and(|x| x.h_merge || x.v_merge);
let templates: Vec<Option<Cell>> = (0..t.rows.len())
.map(|r0| {
let (mut r, mut n) = (r0, neighbour);
while covered(r, n) {
let cell = &t.rows[r].cells[n];
if cell.h_merge && n > 0 {
n -= 1;
} else if cell.v_merge && r > 0 {
r -= 1;
} else {
break;
}
}
r.cells.get(n).cloned()
t.rows[r].cells.get(n).cloned()
})
.collect();
t.insert_col(at);
+13
View File
@@ -6571,6 +6571,19 @@ fn table_insert_column_beside_a_merge_copies_the_anchor_format() {
assert!(t.cell(0, 2).unwrap().fill.is_some());
}
#[test]
fn table_insert_column_beside_a_two_row_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": [1, 1]})).unwrap();
s.execute("table.insertColumnRight", &json!({"id": id.0, "col": 1})).unwrap();
let t = table_of(&s, id);
assert!(t.cell(1, 1).unwrap().h_merge && t.cell(1, 1).unwrap().v_merge, "the merge stays put");
assert!(t.cell(0, 2).unwrap().fill.is_some());
assert_eq!(t.cell(1, 2).unwrap().fill, t.cell(0, 0).unwrap().fill);
}
/// 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.