From 372c0e6c4445fd6aa029a8f11bfca1ec03124c87 Mon Sep 17 00:00:00 2001 From: Hamza Date: Thu, 29 Oct 2026 16:48:32 +0500 Subject: [PATCH] Apply only a date format the caller asked for The dialog always sends `dateText`, so an Apply with no format selection reached `set_date` carrying the deck's global format, and rewrote a slide's own date field to it. Measured on two slides, the first on the time format and the second on the short date: before [datetime11, datetime5] apply {"date": true, "dateText": "", "all": true} after [datetime5, datetime5] The first slide's format was never mentioned by the caller, and it was gone. `set_date` already keeps an existing field when the format is empty, so it now gets an empty format unless `dateFormat` was supplied; a format that is supplied still reaches every slide, which the test checks so the guard cannot quietly become a block. --- crates/engine/src/cmd/design/slide_setup.rs | 33 ++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/design/slide_setup.rs b/crates/engine/src/cmd/design/slide_setup.rs index 86d9317b7..ed91d3253 100644 --- a/crates/engine/src/cmd/design/slide_setup.rs +++ b/crates/engine/src/cmd/design/slide_setup.rs @@ -176,7 +176,12 @@ pub(super) fn header_footer(s: &mut Session, p: &Value) -> Result { } (Some(pos), true) if k == PhType::Date && (date_given || format_given) => { if let Some(sh) = sl.shapes.get_mut(pos) { - set_date(sh, &hf.date_text, &hf.date_format); + // Only a format the caller asked for. The dialog always sends + // `dateText`, so an Apply with no format selection reached here and + // rewrote a slide's own `datetime11` field to the deck's global + // format, which the caller never mentioned (noted in review). No + // format means the field keeps the one it has. + set_date(sh, &hf.date_text, if format_given { &hf.date_format } else { "" }); } } _ => {} @@ -298,6 +303,32 @@ mod header_footer_date_tests { got[0].0.clone() } + /// The dialog always sends `dateText`, so an Apply with no format selection reached + /// `set_date` with the deck's global format and rewrote a slide's own date field to it. The + /// format the caller did not mention is not a format the caller asked for (noted in review). + #[test] + fn an_apply_with_no_format_leaves_each_slides_own_format_alone() { + let mut s = Session::with_new(); + s.execute("slide.new", &json!({})).unwrap(); + s.execute("design.headerFooter", &json!({"date": true, "dateFormat": "datetime11", "all": true})).unwrap(); + let kinds = |s: &Session| dates(s).into_iter().map(|(_, k)| k).collect::>(); + assert_eq!(kinds(&s), vec![Some("datetime11".to_string()); 2], "both slides start on the time format"); + + // One slide alone takes a different format, which also becomes the deck's global one. + s.execute("design.headerFooter", &json!({"date": true, "dateFormat": "datetime5", "all": false})).unwrap(); + assert_eq!(kinds(&s), vec![Some("datetime11".to_string()), Some("datetime5".to_string())]); + assert_eq!(s.doc().unwrap().doc.header_footer.date_format, "datetime5"); + + // Apply with no `dateFormat`: the first slide keeps datetime11 rather than being rewritten + // to the global datetime5. + s.execute("design.headerFooter", &json!({"date": true, "dateText": "", "all": true})).unwrap(); + assert_eq!(kinds(&s), vec![Some("datetime11".to_string()), Some("datetime5".to_string())], "neither slide was rewritten"); + + // And a format that *is* given still reaches every slide, so the guard is not a block. + s.execute("design.headerFooter", &json!({"date": true, "dateFormat": "datetime2", "all": true})).unwrap(); + assert_eq!(kinds(&s), vec![Some("datetime2".to_string()); 2], "a format the caller asked for still applies"); + } + /// Header & Footer's automatic date takes the format it is given. `HeaderFooter::date_format` /// existed for this and was never read: the placeholder was always `datetime1`, and a /// `dateFormat` parameter was accepted and silently dropped.