mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-02 02:33:55 -06:00
paste: a cut is refused over any filter-hidden row it would land on, anchored or tall
The hidden-row check read the rows a tiled single-row paste skips, which is empty for a paste at an explicit cell or a taller block, so those wrote into hidden rows after the source was cleared. It now checks the cut's own destination rows.
This commit is contained in:
@@ -94,8 +94,14 @@ pub(super) fn paste_special(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
"The cut cells and the paste area aren't the same size and shape: select one cell, or an area the size of the cut cells.".into(),
|
||||
));
|
||||
}
|
||||
if skip_rows.range(at.row..at.row.saturating_add(tiles_r.saturating_mul(h))).next().is_some() {
|
||||
return Err(EngineError::Other("The cut area can't be pasted into rows the filter hides.".into()));
|
||||
// The rows the cut itself would land on, whatever the paste would skip: an anchored or
|
||||
// taller block is pasted straight down, so `skip_rows` (which only a tiled single row uses)
|
||||
// can't tell whether it would write into a hidden row.
|
||||
if let Some(end) = at.offset(i64::from(h) - 1, i64::from(w) - 1) {
|
||||
let dest = RangeRef::new(at, end);
|
||||
if s.doc()?.wb.sheet(dest_sheet).is_some_and(|sh| !super::filtered_rows(sh, dest).is_empty()) {
|
||||
return Err(EngineError::Other("The cut area can't be pasted into rows the filter hides.".into()));
|
||||
}
|
||||
}
|
||||
}
|
||||
let src_wb = clip.wb.clone();
|
||||
|
||||
@@ -7160,6 +7160,28 @@ fn a_cut_is_not_pasted_into_filtered_rows() {
|
||||
assert_eq!((v(&s, "A4"), v(&s, "B4"), v(&s, "E1")), (Value::Number(1.0), Value::Number(2.0), Value::Empty));
|
||||
}
|
||||
|
||||
/// A taller cut, or one pasted at an explicit cell, goes straight down: refused when a row the
|
||||
/// filter hides is among the rows it would land on, and nothing changes. A visible place takes it.
|
||||
#[test]
|
||||
fn an_anchored_cut_is_not_pasted_over_filtered_rows() {
|
||||
let mut s = s();
|
||||
let mut rows = vec![json!(["Val", "Tag"])];
|
||||
for i in 2..=5 {
|
||||
rows.push(json!([format!("v{i}"), if i == 3 { "hide" } else { "keep" }]));
|
||||
}
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": rows})).unwrap();
|
||||
s.execute("range.setValues", json!({"range": "A10", "values": [[1, 2], [3, 4]]})).unwrap();
|
||||
s.execute("selection.set", json!({"range": "A1:B1"})).unwrap();
|
||||
s.execute("data.filter", json!({})).unwrap();
|
||||
s.execute("data.filterBy", json!({"column": "B", "values": ["keep"]})).unwrap();
|
||||
s.execute("edit.cut", json!({"range": "A10:B11"})).unwrap();
|
||||
assert!(s.execute("edit.paste", json!({"at": "A2"})).is_err());
|
||||
assert_eq!((v(&s, "A10"), v(&s, "B11")), (Value::Number(1.0), Value::Number(4.0)));
|
||||
assert_eq!((v(&s, "A2"), v(&s, "A3")), (Value::from("v2"), Value::from("v3")));
|
||||
s.execute("edit.paste", json!({"at": "A4"})).unwrap();
|
||||
assert_eq!((v(&s, "A4"), v(&s, "B5"), v(&s, "A10")), (Value::Number(1.0), Value::Number(4.0), Value::Empty));
|
||||
}
|
||||
|
||||
/// Skip Blanks would empty a cut's blank cells along with their note and format, then skip them:
|
||||
/// a cut takes no Paste Special option, and nothing changes.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user