mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-09 20:09:57 -06:00
Engine: a Hidden cell on a protected sheet hides its Python code
A cell formatted Hidden on a protected sheet hid its formula but not its Python code: display::formula_hidden only looked for a formula at the cell (a Python cell was covered only while its result spilled), and the formula bar had its own check for formulas alone. Both now treat Python code as they treat a formula, so the formula bar shows nothing for a hidden Python cell, as it does for a hidden formula. Editing the cell is refused as before, because it is locked.
This commit is contained in:
@@ -296,3 +296,23 @@ fn replace_leaves_python_code_that_would_no_longer_fit() {
|
||||
assert_eq!(r["skipped"], 1);
|
||||
assert_eq!(code(&s, 0, "A1").as_deref(), Some(long.as_str()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hidden_python_cell_on_a_protected_sheet_hides_its_code() {
|
||||
let mut s = s();
|
||||
s.execute("python.set", json!({"cell": "A1", "code": "secret = 1\nsecret"})).unwrap();
|
||||
s.execute("python.set", json!({"cell": "B1", "code": "'shown'"})).unwrap();
|
||||
s.execute("home.formatCells", json!({"range": "A1", "style": {"protection": {"locked": true, "hidden": true}}})).unwrap();
|
||||
let hidden = |s: &Session, a: &str| {
|
||||
let d = s.doc().unwrap();
|
||||
let sh = d.wb.active().unwrap();
|
||||
crate::display::formula_hidden(&d.wb, sh, CellRef::parse(a).unwrap())
|
||||
};
|
||||
assert!(!hidden(&s, "A1"), "an unprotected sheet hides nothing");
|
||||
s.execute("review.protectSheet", json!({})).unwrap();
|
||||
assert!(hidden(&s, "A1"), "Hidden on a protected sheet hides the code, as it hides a formula");
|
||||
assert!(!hidden(&s, "B1"));
|
||||
// Editing it is refused where a formula's would be: the cell is locked.
|
||||
assert!(s.execute("python.set", json!({"cell": "A1", "code": "2"})).is_err());
|
||||
assert_eq!(code(&s, 0, "A1").as_deref(), Some("secret = 1\nsecret"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user