diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index fb899c702..3e197efaf 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -393,7 +393,11 @@ impl Dialog { Text { key: "header", label: "Header (&L left, &C center, &R right; &P page, &N pages, &D date, &A sheet):" }, Text { key: "footer", label: "Footer:" }, ], - json!({"header": "", "footer": "&CPage &P of &N"}), + { + let sheet = app.session.active().and_then(|d| d.wb.active()); + let (header, footer) = sheet.map(|s| (s.print.header.clone(), s.print.footer.clone())).unwrap_or_default(); + json!({"header": header, "footer": footer}) + }, ), "pageSetup" => { // Opens on the active sheet's saved margins, so OK without edits rewrites them unchanged. diff --git a/crates/ui-egui/tests/interaction.rs b/crates/ui-egui/tests/interaction.rs index 02084ffb8..80fe04395 100644 --- a/crates/ui-egui/tests/interaction.rs +++ b/crates/ui-egui/tests/interaction.rs @@ -911,3 +911,21 @@ fn undo_after_backspace_restores_the_cleared_cell() { assert_eq!(value(&h, "A1"), Value::Number(3200.0)); assert_eq!(value(&h, "C5"), Value::Number(11750.0)); } + +#[test] +fn header_footer_dialog_opens_on_the_saved_header_and_footer() { + // #523: the dialog started from a fixed empty header and `&CPage &P of &N`, so OK replaced the sheet's text. + let mut s = blank(); + s.execute("pageLayout.headerFooter", json!({"header": "&LLeft", "footer": "&CConfidential"})).unwrap(); + let mut h = harness(s); + h.state_mut().open_dialog("headerFooter", json!({})); + h.run_steps(2); + let d = h.state_mut().dialog.as_mut().unwrap(); + assert_eq!(d.values["header"], json!("&LLeft")); + assert_eq!(d.values["footer"], json!("&CConfidential")); + d.values.insert("header".into(), json!("&CNew")); + let vals = json!(d.values.clone()); + h.state_mut().run("pageLayout.headerFooter", vals).unwrap(); + let pr = &h.state().session.active().unwrap().wb.active().unwrap().print; + assert_eq!((pr.header.as_str(), pr.footer.as_str()), ("&CNew", "&CConfidential")); +}