mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 18:23:52 -06:00
Insert column: copy the merge anchor's format when the neighbour is covered
A neighbour cell covered by a horizontal merge has no formatting of its own, so the inserted cell looked different from what is shown. Resolve it to the leftmost anchor before copying. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
555e12c1a0
commit
f0c202dca8
@@ -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<Option<Cell>> = 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<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;
|
||||
}
|
||||
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)) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user