From 2edd5edbadcc13f20ed4468ccf8815bb67201054 Mon Sep 17 00:00:00 2001 From: Lucas Batista Vargas Date: Wed, 25 Nov 2026 13:21:42 -0300 Subject: [PATCH] font-manager: restore Plain FontPicker text click vs chevron parity (#3102) (#3103) --- crates/font-manager/src/picker.rs | 22 ++++++-- crates/font-manager/tests/it/picker.rs | 73 ++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/crates/font-manager/src/picker.rs b/crates/font-manager/src/picker.rs index 6e3856bb59..ddc00559f9 100644 --- a/crates/font-manager/src/picker.rs +++ b/crates/font-manager/src/picker.rs @@ -621,6 +621,7 @@ struct Typing { hide_classes: bool, expanded: Vec, rested: Vec, + focused: bool, } /// The interface language code of the host, English without one. @@ -666,7 +667,10 @@ enum Stop { } /// The font family field. Typing filters the list to the families whose name (in any language) matches, the best -/// match first, and opens it; a click on the name while the list is closed, the chevron and Alt+Down open it on every family (the click selects the name), Alt+Up closes it. Rows: a star, the +/// match first, and opens it; in the library picker a click on the name while the list is closed opens it on every +/// family and selects the name, whereas in `Plain` only a click that focuses the field selects the name without opening +/// the list (subsequent clicks place the caret). The chevron and Alt+Down open the list on every family, and Alt+Up +/// closes it. Rows: a star, the /// family name in the interface face, the sample text (the preview text, else "Sample") in the family's own face at the /// preview size and the class mark. /// Recent families form a group at the top. Up, Down and Page keys move the keyboard row, which previews, Enter or a @@ -977,6 +981,8 @@ impl Component for FontPicker<'_> { if !self.catalog.is_ready() { return; } + let focused = cx.is_focused(); + let was_focused = std::mem::replace(&mut cx.memory::().focused, focused); let list = cx.popup(POPUP); let draft = cx.text(&text_key()).and_then(|outcome| outcome.draft.clone()); let before = std::mem::replace(&mut cx.memory::().draft, draft.clone()); @@ -992,10 +998,18 @@ impl Component for FontPicker<'_> { } } // A click on the name while the list is closed opens it on every family and selects the name, so typing - // replaces it (Photoshop's font field). + // replaces it (Photoshop's font field). In Word's plain font picker, clicking selects the name without + // auto-opening the popup list so the user can immediately type a replacement family. Subsequent clicks on + // an already-focused plain field place the caret rather than re-selecting all text. if !list.is_open(cx) && cx.text(&text_key()).is_some_and(|outcome| outcome.clicked) { - cx.select_all_text(); - list.open(cx); + if self.kind == FontPickerKind::Plain { + if !was_focused { + cx.select_all_text(); + } + } else { + cx.select_all_text(); + list.open(cx); + } } if list.is_open(cx) { return; diff --git a/crates/font-manager/tests/it/picker.rs b/crates/font-manager/tests/it/picker.rs index 01f5653004..937d9ec51c 100644 --- a/crates/font-manager/tests/it/picker.rs +++ b/crates/font-manager/tests/it/picker.rs @@ -575,6 +575,9 @@ fn a_plain_box_commits_an_unknown_typed_name_lists_recents_first_and_again_after fx.settle(); let field = fx.by_label("Font family").expect("the family field"); + // Unfocus after Escape so the click below is a focusing click that selects all text in Plain mode. + fx.click_at(field.rect.right_center() + egui::vec2(20.0, 0.0)); + fx.settle(); fx.click(&field); fx.settle(); fx.type_text("x"); @@ -592,6 +595,76 @@ fn a_plain_box_commits_an_unknown_typed_name_lists_recents_first_and_again_after assert_eq!(seen.borrow().picks.last().map(|(picked, _)| picked.as_str()), Some("Zapfino")); } +#[trial] +fn clicking_the_font_field_selects_all_without_opening_dropdown_and_chevron_toggles() { + let catalog = catalog_of(&[INTER_REGULAR, epaint_default_fonts::HACK_REGULAR]); + let (mut fx, _seen) = plain_rig(catalog, "Inter", &["Hack"], vec![], None); + let words = FontPickerWords::default(); + let (recently, all) = (words.recently_used.as_str(), words.all_fonts.as_str()); + + // 1. Clicking the text field focuses and selects all text without opening the dropdown popup + let field = fx.by_label("Font family").expect("the family field"); + fx.click(&field); + fx.settle(); + assert!(!present(&fx, recently), "recently used fonts do not open on field click"); + assert!(!present(&fx, all), "all fonts do not open on field click"); + + // 2. Typing in the field opens the dropdown filtered on matches + fx.type_text("Ha"); + fx.settle(); + assert!(present(&fx, "Hack"), "typing in the field opens the dropdown with matches"); + + // Pressing Enter commits the typed family and closes the dropdown + fx.key(Key::Enter, Modifiers::NONE); + fx.settle(); + fx.frame(vec![]); + fx.settle(); + assert!(!present(&fx, all), "committing typed query closes the dropdown"); + + // 3. Clicking the dropdown arrow (chevron) toggles the dropdown list open + let chevron = fx.by_label(words.list.as_str()).expect("the chevron button"); + fx.click(&chevron); + fx.settle(); + assert!(present(&fx, recently), "recently used fonts show up on chevron click"); + assert!(present(&fx, all), "all fonts show up on chevron click"); + + // 4. Clicking inside the field while already open keeps dropdown open + let field = fx.by_label("Font family").expect("the family field"); + fx.click(&field); + fx.settle(); + assert!(present(&fx, all), "dropdown remains open on click inside field"); + + // 5. Clicking the chevron button again toggles the dropdown closed + let chevron = fx.by_label(words.list.as_str()).expect("the chevron button"); + fx.click(&chevron); + fx.settle(); + fx.frame(vec![]); + fx.settle(); + assert!(!present(&fx, all), "dropdown closes on chevron click toggle"); +} + +#[trial] +fn clicking_the_focused_plain_box_places_caret_instead_of_selecting_all() { + let catalog = catalog_of(&[INTER_REGULAR, epaint_default_fonts::HACK_REGULAR]); + let (mut fx, _seen) = plain_rig(catalog, "Inter", &["Hack"], vec![], None); + let field = fx.by_label("Font family").expect("the family field"); + + // 1. The first click gives the field focus and selects all text + fx.click(&field); + fx.settle(); + + // 2. Clicking again after double-click interval places the caret before the "I" without re-selecting all + fx.advance(1.0); + fx.click_at(field.rect.left_center() + egui::vec2(6.0, 0.0)); + fx.settle(); + + // 3. Typing "Ha" inserts before "Inter" producing "HaInter" rather than replacing the text with "Ha" + fx.type_text("Ha"); + fx.settle(); + assert!(present(&fx, "HaInter"), "typing inserts at placed caret before the existing family name"); + assert!(!present(&fx, "Hack"), "Hack is not suggested because draft is HaInter, not Ha"); +} + #[trial] fn an_action_row_is_reported_not_committed_and_a_missing_family_shows_the_note_naming_the_face() { let words = MissingFontsWords::default();