Merge pull request #8797

This commit is contained in:
autocraft-bot[bot]
2026-12-04 15:31:54 +00:00
5 changed files with 43 additions and 48 deletions
+2
View File
@@ -138,6 +138,8 @@ impl WordApp {
saves_in_flight: Vec::new(),
fallback_chooser: false,
font_generation: wordcraft_fonts::FontDb::global().generation(),
#[cfg(test)]
font_catalog: None,
recovery_seen: false,
no_document: None,
parked: Default::default(),
+4
View File
@@ -437,6 +437,10 @@ pub struct WordApp {
/// The font database's [`generation`](wordcraft_fonts::FontDb::generation) last seen: when
/// fonts are added or removed (by any route) the font lists and the layout are refreshed.
font_generation: u64,
/// Test-only catalog override so UI tests list only fixed `assets/fonts/` without scanning
/// the host's system fonts.
#[cfg(test)]
pub(crate) font_catalog: Option<std::sync::Arc<craft::font_manager::Catalog>>,
/// Focus (#1678): the ribbon is dropped down from the Focus bar, over the page. The shell
/// owns the flag while it draws; the app reads it back after each pass.
pub(crate) ribbon_dropped: bool,
+8 -3
View File
@@ -91,9 +91,9 @@ pub fn font_picker<'a>(
pub fn font_box(ui: &mut Ui, app: &mut WordApp, label: impl Into<Label>, family: &mut String) -> FontPickerOutput {
let warning = app.font_box_warning(family);
let rows = actions();
let catalog = Catalog::global();
let catalog = app.font_catalog();
// PLAN: assumed `UiState::font_picker: FontPickerSettings`, replacing `recent_fonts` (app-hub).
let out = font_picker(label, Bind::bound(family), catalog, Bind::bound(&mut app.ui.font_picker), &rows, warning.as_deref()).show(ui);
let out = font_picker(label, Bind::bound(family), &catalog, Bind::bound(&mut app.ui.font_picker), &rows, warning.as_deref()).show(ui);
if let Some(command) = out.action.and_then(action_command) {
let _ = app.run(command, json!({}));
}
@@ -101,8 +101,13 @@ pub fn font_box(ui: &mut Ui, app: &mut WordApp, label: impl Into<Label>, family:
}
impl WordApp {
/// The font catalog every font box lists: the process's one catalog.
/// The font catalog every font box lists: the process's one catalog (or an isolated test
/// catalog when set).
pub(crate) fn font_catalog(&self) -> Arc<Catalog> {
#[cfg(test)]
if let Some(catalog) = &self.font_catalog {
return Arc::clone(catalog);
}
Arc::clone(Catalog::global())
}
+27 -45
View File
@@ -1,5 +1,8 @@
use std::path::Path;
use std::sync::Arc;
use craft::font_manager::Catalog;
use craft::font_manager::craft_font_catalog::{Limits, Source};
use craft::font_manager::craft_font_catalog::{FontEnv, Os};
use craft::ui::buttons::IconButton;
use craft::ui::contract::{Props as _, Show as _};
use egui::accesskit::Role;
@@ -10,25 +13,14 @@ use wordcraft_engine::Session;
use crate::{Services, WordApp};
fn ensure_catalog_ready() {
let catalog = Catalog::global();
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());
}
}
fn fixed_catalog() -> Arc<Catalog> {
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.is_ready(), "fixed font catalog scanned synchronously");
assert!(catalog.families().iter().any(|f| f == "Inter"), "fixed catalog loaded assets/fonts");
catalog
}
fn open_ribbon_font_box(h: &mut egui_kittest::Harness<'static, WordApp>) {
@@ -59,10 +51,11 @@ fn current_font(h: &mut egui_kittest::Harness<'static, WordApp>) -> Option<Strin
/// when recent fonts exist, and Arrow-Down skips section headings rather than landing on them.
#[test]
fn font_list_sections_skip_their_headings() {
ensure_catalog_ready();
let catalog = fixed_catalog();
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Sample")), Services::default());
app.ui.language = "en".into();
app.font_catalog = Some(Arc::clone(&catalog));
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| app);
h.run_steps(4);
@@ -89,6 +82,7 @@ fn font_list_sections_skip_their_headings() {
// heading and land on `first_all`, so Enter switches the document font to `first_all`.
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Sample")), Services::default());
app.ui.language = "en".into();
app.font_catalog = Some(catalog);
app.run("format.font", json!({"name": chosen_recent})).unwrap();
assert_eq!(app.ui.font_picker.recent, [chosen_recent.as_str()]);
assert_eq!(app.session.run("format.state", &json!({})).unwrap().get("font").and_then(Value::as_str), Some(chosen_recent.as_str()));
@@ -237,10 +231,10 @@ fn drawn_buttons_fade_in_on_hover_and_darken_while_pressed() {
#[test]
fn the_typed_list_shows_on_the_frame_of_the_keystroke() {
const RECENT: &str = "Source Serif 4";
ensure_catalog_ready();
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Sample")), Services::default());
app.ui.language = "en".into();
app.font_catalog = Some(fixed_catalog());
app.ui.font_picker.recent = vec![RECENT.to_string()];
let mut family = String::new();
@@ -268,12 +262,12 @@ 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("!".into())], &[], &[RECENT, "Inter", "JetBrains Mono"], false),
(erase(), &[RECENT], &[], true),
(erase(), &[RECENT, "Inter", "JetBrains Mono"], &[], 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], &[], true),
(erase(), &[RECENT, "Inter", "JetBrains Mono"], &[], true),
(vec![egui::Event::Text("int".into())], &["Inter"], &["JetBrains Mono"], false),
];
@@ -302,27 +296,15 @@ 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 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");
}
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"
);
}
}
+2
View File
@@ -156,6 +156,8 @@ impl WordApp {
print_feedback_seen: _,
print_gen: _,
font_generation: _,
#[cfg(test)]
font_catalog: _,
updates_rt: _,
font_notice_seen: _,
font_notices: _,