mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-24 10:46:50 -06:00
Conditional formats: a style fill of "none" means no fill
`style: {fill: "none"}` (or "auto") went through the colour pass and came out as a solid
fill in the automatic colour. `home.fillColor` reads the same word as no fill, so the rule
style does too now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
151a279da8
commit
2a580f2902
@@ -1274,8 +1274,8 @@ fn is_string_literal(v: &str) -> bool {
|
||||
/// A conditional format's `style` as the model's `Style` JSON (`font`, `fill`, `borders`, `align`,
|
||||
/// `num_fmt`, `protection`, merged over the default by the caller), where a colour may also be
|
||||
/// written as `format_range` takes it (`"#RRGGBB"`, `{theme, tint}`, `"auto"`) and `fill` may be a
|
||||
/// colour alone (a solid fill). An unknown key is an error rather than dropped: dropped, it left a
|
||||
/// rule with an empty format that matches and shows nothing.
|
||||
/// colour alone (a solid fill) or `"none"` (no fill). An unknown key is an error rather than
|
||||
/// dropped: dropped, it left a rule with an empty format that matches and shows nothing.
|
||||
fn cf_style_json(st: &Json) -> Result<Json> {
|
||||
const KEYS: [&str; 6] = ["font", "fill", "borders", "align", "num_fmt", "protection"];
|
||||
let err = |m: String| bad("home.conditionalFormat", m);
|
||||
@@ -1299,7 +1299,10 @@ fn cf_style_json(st: &Json) -> Result<Json> {
|
||||
color(c, "font.color")?;
|
||||
}
|
||||
if let Some(fill) = st.get_mut("fill") {
|
||||
if fill.is_string() || fill.get("theme").is_some() {
|
||||
// `"none"` (or `"auto"`) is no fill, as `home.fillColor` reads it, not a solid automatic one.
|
||||
if fill.is_string() && super::format::color_param(Some(fill)) == Some(Color::Auto) {
|
||||
*fill = serde_json::to_value(Fill::default()).map_err(|e| EngineError::Other(e.to_string()))?;
|
||||
} else if fill.is_string() || fill.get("theme").is_some() {
|
||||
*fill = json!({"pattern": "Solid", "fg": fill.clone()});
|
||||
}
|
||||
if let Some(f) = fill.as_object_mut() {
|
||||
|
||||
@@ -2643,6 +2643,14 @@ fn conditional_format_styles_take_hex_colours_and_quoted_values() {
|
||||
s.execute("home.conditionalFormat", json!({"range": "A1", "rule": {"type": "expression", "formula": "=TRUE", "style": internal}})).unwrap();
|
||||
let st = style(&rule(&s, 0));
|
||||
assert_eq!((st.fill.fg, st.borders.left.color), (Color::Rgb(0xFFF2CC), Color::Rgb(0xC00000)));
|
||||
// `"none"` is no fill (the format only sets the font), as `home.fillColor` reads it.
|
||||
s.execute(
|
||||
"home.conditionalFormat",
|
||||
json!({"range": "A1", "rule": {"type": "expression", "formula": "=TRUE", "style": {"fill": "none", "font": {"bold": true}}}}),
|
||||
)
|
||||
.unwrap();
|
||||
let st = style(&rule(&s, 0));
|
||||
assert_eq!((st.fill, st.font.bold), (Fill::default(), true));
|
||||
// Keys that would be dropped, leaving a rule that shows nothing, are refused.
|
||||
let n = s.doc().unwrap().wb.active().unwrap().cond_formats.len();
|
||||
for bad in [json!({"preset": "greenFill"}), json!({"fillColor": "#FFF2CC"}), json!({"fill": "#nothex"}), json!("bold")] {
|
||||
|
||||
Reference in New Issue
Block a user