diff --git a/crates/ui-egui/src/options.rs b/crates/ui-egui/src/options.rs index 3096989428..94d72e1d5d 100644 --- a/crates/ui-egui/src/options.rs +++ b/crates/ui-egui/src/options.rs @@ -129,6 +129,8 @@ struct Strings { numeral_id: String, proofing_language: String, autosave_reason: String, + /// The Initials box's placeholder: the initials an empty box falls back to (#8018). + initials_hint: String, } impl Strings { @@ -199,6 +201,7 @@ impl Strings { numeral_id, proofing_language, autosave_reason: crate::AutoSaveBlock::Browser.reason().to_string(), + initials_hint: app.session.user_initials(), } } } @@ -357,7 +360,7 @@ impl PreferencesModel for OptionsModel<'_> { Some(tl!("Personalize")), vec![ RowSpec::new("general.userName", tl!("User name:"), RowKind::Text(&app.session.author)).enabled(!protected), - RowSpec::new("general.initials", tl!("Initials:"), RowKind::Text(&app.session.initials)), + RowSpec::new("general.initials", tl!("Initials:"), RowKind::Text(&app.session.initials)).placeholder(&s.initials_hint), ], ), ], diff --git a/crates/ui-egui/src/options/tests.rs b/crates/ui-egui/src/options/tests.rs index 0baccded34..8217771c08 100644 --- a/crates/ui-egui/src/options/tests.rs +++ b/crates/ui-egui/src/options/tests.rs @@ -539,3 +539,36 @@ fn folder_settings_have_apply_and_clear() { } let _ = std::fs::remove_dir_all(&dir); } + +/// #8018: an empty Initials box paints the initials it falls back to. +#[test] +fn empty_initials_box_paints_the_default_initials() { + fn painted(shapes: &[egui::epaint::ClippedShape], out: &mut Vec) { + fn walk(shape: &egui::Shape, out: &mut Vec) { + match shape { + egui::Shape::Text(t) => out.push(t.galley.text().to_string()), + egui::Shape::Vec(v) => v.iter().for_each(|c| walk(c, out)), + _ => {} + } + } + shapes.iter().for_each(|c| walk(&c.shape, out)); + } + let shown = || { + let mut a = app(); + a.session.author = "Zora Quentin".into(); + a.run("ui.backstage", json!({"value": true, "page": "options", "pane": "general"})).unwrap(); + let mut h = crate::test_harness::builder().build_ui_state( + |ui, app: &mut WordApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + a, + ); + options_frames(&mut h, 3); + let mut texts = Vec::new(); + painted(&h.output().shapes, &mut texts); + texts + }; + assert!(shown().iter().any(|t| t == "ZQ"), "empty box paints the default initials"); +}