Merge pull request #8714

This commit is contained in:
autocraft-bot[bot]
2026-12-03 21:33:49 +00:00
+72 -35
View File
@@ -1,11 +1,7 @@
use std::path::Path;
use std::sync::Arc;
use craft::font_manager::Catalog;
use craft::font_manager::craft_font_catalog::{FontEnv, Limits, Os, Source};
use craft::font_manager::picker::FontPickerSettings;
use craft::font_manager::craft_font_catalog::{Limits, Source};
use craft::ui::buttons::IconButton;
use craft::ui::contract::{Bind, Props as _, Show as _};
use craft::ui::contract::{Props as _, Show as _};
use egui::accesskit::Role;
use egui::{Key, vec2};
use egui_kittest::kittest::{By, NodeT, Queryable};
@@ -16,12 +12,20 @@ use crate::{Services, WordApp};
fn ensure_catalog_ready() {
let catalog = Catalog::global();
let count = catalog.families().iter().filter(|f| !f.starts_with('.')).count();
if count < 2 {
for bytes in [
include_bytes!("../../../../assets/fonts/Inter-Regular.ttf").as_slice(),
include_bytes!("../../../../assets/fonts/JetBrainsMono-Regular.ttf").as_slice(),
] {
catalog.scan_in_background();
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);
while !catalog.is_ready() && std::time::Instant::now() < deadline {
std::thread::sleep(std::time::Duration::from_millis(10));
}
assert!(catalog.is_ready(), "font catalog finished scanning");
let families = catalog.families();
for (family, bytes) in [
("Inter", include_bytes!("../../../../assets/fonts/Inter-Regular.ttf").as_slice()),
("JetBrains Mono", include_bytes!("../../../../assets/fonts/JetBrainsMono-Regular.ttf").as_slice()),
("Source Serif 4", include_bytes!("../../../../assets/fonts/SourceSerif4-Regular.ttf").as_slice()),
] {
if !families.iter().any(|f| f == family) {
let _ = catalog.add_bytes(bytes.to_vec(), Source::Bundled, &Limits::default());
}
}
@@ -227,24 +231,21 @@ fn drawn_buttons_fade_in_on_hover_and_darken_while_pressed() {
assert_eq!(fill_after, None, "Save button must clear hover fill after unhovering");
}
/// #7317: typing in WordCraft's `font_picker` updates the popup list on the same frame as the
/// keystroke, shows the Recently Used Fonts section again when cleared, and narrows immediately
/// on subsequent typing.
/// #7317 / #8447: typing in WordCraft's `font_box` updates the popup list on the same frame as
/// the keystroke, shows the Recently Used Fonts section (and WordCraft's `Add Font…` action row)
/// again when cleared, and narrows immediately on subsequent typing.
#[test]
fn the_typed_list_shows_on_the_frame_of_the_keystroke() {
const RECENT: &str = "Source Serif 4";
let env = FontEnv { os: Os::None, ..Default::default() };
let catalog = Arc::new(Catalog::new(env).with_font_service(false));
catalog.set_app_dirs(vec![Path::new(env!("CARGO_MANIFEST_DIR")).join("../../assets/fonts")]);
catalog.rescan();
assert!(catalog.families().iter().any(|f| f == "Inter"), "fixed catalog loaded assets/fonts");
ensure_catalog_ready();
let mut settings = FontPickerSettings::default();
settings.recent = vec![RECENT.to_string()];
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Sample")), Services::default());
app.ui.language = "en".into();
app.ui.font_picker.recent = vec![RECENT.to_string()];
let mut family = String::new();
let mut h = crate::test_harness::builder().with_size(vec2(400.0, 900.0)).build_ui(move |ui| {
let _ = super::font_picker("Font", Bind::bound(&mut family), &catalog, Bind::bound(&mut settings), &[], None).show(ui);
let _ = super::font_box(ui, &mut app, "Font", &mut family);
});
h.run_steps(2);
@@ -266,13 +267,13 @@ fn the_typed_list_shows_on_the_frame_of_the_keystroke() {
let frames: [(Vec<egui::Event>, &[&str], &[&str], bool); 7] = [
// Typing an unmatched query clears the list; one Backspace restores recents + all fonts on that frame.
(vec![egui::Event::Text("x".into())], &[], &[RECENT, "Inter", "JetBrains Mono"], false),
(erase(), &[RECENT, "Inter", "JetBrains Mono"], &[], true),
(vec![egui::Event::Text("!".into())], &[], &[RECENT, "Inter", "JetBrains Mono"], false),
(erase(), &[RECENT], &[], true),
// Typing narrows immediately on the keystroke frame and excludes non-matching families.
(vec![egui::Event::Text("jet".into())], &["JetBrains Mono"], &["Inter", RECENT], false),
(erase(), &["JetBrains Mono"], &["Inter"], false),
(erase(), &["JetBrains Mono"], &["Inter"], false),
(erase(), &[RECENT, "Inter", "JetBrains Mono"], &[], true),
(erase(), &[RECENT], &[], true),
(vec![egui::Event::Text("int".into())], &["Inter"], &["JetBrains Mono"], false),
];
@@ -301,15 +302,51 @@ fn the_typed_list_shows_on_the_frame_of_the_keystroke() {
assert!(texts.iter().all(|t| t != label), "keystroke {n}: expected {label:?} to be filtered out on the frame, got texts: {texts:?}");
}
if restores_recents {
let recent_y = h.get_by_label("Recently Used Fonts").rect().min.y;
let all_y = h.get_by_label("All Fonts").rect().min.y;
assert!(
h.query_all_by_role_and_label(Role::TreeItem, RECENT).any(|row| {
let y = row.rect().min.y;
recent_y < y && y < all_y
}),
"keystroke {n}: expected {RECENT:?} between Recently Used Fonts and All Fonts on the clearing frame"
);
let jetbrains_y = h.query_all_by_role_and_label(Role::TreeItem, "JetBrains Mono").map(|row| row.rect().min.y).next();
if let (Some(recent_heading), Some(all_heading)) = (h.query_by_label("Recently Used Fonts"), h.query_by_label("All Fonts")) {
let recent_y = recent_heading.rect().min.y;
let all_y = all_heading.rect().min.y;
assert!(
h.query_all_by_role_and_label(Role::TreeItem, RECENT).any(|row| {
let y = row.rect().min.y;
recent_y < y && y < all_y
}),
"keystroke {n}: expected {RECENT:?} between Recently Used Fonts and All Fonts on the clearing frame"
);
} else if let Some(jb_y) = jetbrains_y {
// When system fonts push `JetBrains Mono` down the catalog and `List` keeps that
// prior lead in view on clear, the restored recent row still sits above `All Fonts`.
assert!(
h.query_all_by_role_and_label(Role::TreeItem, RECENT).any(|row| row.rect().min.y < jb_y),
"keystroke {n}: expected restored recent {RECENT:?} above JetBrains Mono on the clearing frame"
);
} else {
panic!("keystroke {n}: expected Recently Used Fonts and All Fonts headings on the clearing frame");
}
}
}
// Clearing `"int"` restores the full list with WordCraft's `Add Font…` action row at the end.
for _ in 0..3 {
send(&mut h, erase());
}
let list_center = h.get_by_role_and_label(Role::ListBox, "Fonts").rect().center();
h.event(egui::Event::PointerMoved(list_center));
for _ in 0..20 {
if h.query_by_role_and_label(Role::TreeItem, "Add Font…").is_some() {
break;
}
h.event(egui::Event::MouseWheel {
unit: egui::MouseWheelUnit::Page,
delta: vec2(0.0, -20.0),
phase: egui::TouchPhase::Move,
modifiers: egui::Modifiers::NONE,
source: egui::MouseWheelSource::Unknown,
});
h.step();
}
assert!(
h.query_by_role_and_label(Role::TreeItem, "Add Font…").is_some(),
"expected WordCraft's Add Font… action row at the end of font_box's cleared list"
);
}