Merge PR #1337: Selection: whole columns and rows don't widen to merged cells

This commit is contained in:
aiongg
2026-10-22 02:34:33 +00:00
2 changed files with 20 additions and 1 deletions
+5 -1
View File
@@ -63,9 +63,13 @@ impl Selection {
pub fn a1(&self) -> String {
self.ranges.iter().map(|r| r.a1()).collect::<Vec<_>>().join(",")
}
/// Expands areas so merged cells are included whole.
/// Expands areas so merged cells are included whole. Whole columns and whole rows stay as
/// they are: clicking column B's header selects just B even when B1:C1 is merged, as in Excel.
pub fn expand_merges(&mut self, sheet: &Sheet) {
for r in self.ranges.iter_mut() {
if r.is_full_cols() || r.is_full_rows() {
continue;
}
let mut cur = *r;
loop {
let mut grown = cur;
+15
View File
@@ -2303,6 +2303,21 @@ fn whole_sheet_selection_stays_within_the_data() {
assert!(s.execute("data.removeDuplicates", json!({"range": "A1:XFD1048576", "header": false})).is_ok());
}
#[test]
fn whole_columns_and_rows_ignore_merges_but_cell_ranges_take_them_whole() {
// As in Excel: a merged A2:C2 doesn't widen a click on column B's header to A:C, nor a
// merged B2:B4 a click on row 3's header to rows 2:4; a cell range still takes them whole.
let mut s = s();
s.execute("home.mergeCenter", json!({"range": "A2:C2"})).unwrap();
s.execute("home.mergeCenter", json!({"range": "E2:E4"})).unwrap();
let sel = |s: &mut Session, range: &str| s.execute("selection.set", json!({"range": range})).unwrap()["selection"].clone();
assert_eq!(sel(&mut s, "B:B"), "B:B");
assert_eq!(sel(&mut s, "A:B"), "A:B");
assert_eq!(sel(&mut s, "3:3"), "3:3");
assert_eq!(sel(&mut s, "B1:B3"), "A1:C3");
assert_eq!(sel(&mut s, "E3"), "E2:E4");
}
#[test]
fn parity_counts() {
let (done, total) = crate::catalog::parity();