Merge pull request #10810 from dotCooCoo/fix/new-document-recent-heading

New Document: Recent is headed as recent items and Saved is the second tab
This commit is contained in:
.CooCoo
2026-12-04 03:19:39 -08:00
committed by GitHub
+33 -1
View File
@@ -726,7 +726,7 @@ pub fn open(app: &mut VectorcraftApp) {
}
let recent: Vec<VcNewDocument> = app.session.prefs.recent_new_docs.iter().cloned().map(VcNewDocument::of).collect();
let mut dialog = HostedNewDocument::<VcNewDocument>::new(&ctx, first, move |options| {
NewDocumentDialog::over(Bind::bound(options)).categories(categories.clone()).setup(setup.clone())
NewDocumentDialog::over(Bind::bound(options)).categories(categories.clone()).setup(setup.clone()).saved_after_recent(true).recent_items(true)
})
.saved(saved)
.recent(recent);
@@ -1255,6 +1255,38 @@ mod tests {
}
}
/// Recent is headed as the recent documents it lists, and Saved is the second tab, right after Recent; before,
/// Recent read "Blank Document Presets (n)" and Saved was the last tab.
#[test]
fn recent_heads_its_documents_and_saved_follows_it() {
use egui::accesskit::Role;
let mut app = app();
app.run("file.new", json!({"preset": "Letter"})).unwrap();
app.run("file.new", json!({"preset": "Web 1920×1080"})).unwrap();
open(&mut app);
let out = laid_out(&mut app);
let drawn: Vec<String> = crate::tests_labels::text_shapes(&out).into_iter().map(|(t, _)| t.galley.text().to_uppercase()).collect();
assert!(drawn.iter().any(|t| t == "YOUR RECENT ITEMS (2)"), "Recent counts its two documents: {drawn:?}");
assert!(!drawn.iter().any(|t| t.starts_with("BLANK DOCUMENT PRESETS")), "Recent is not headed as presets: {drawn:?}");
// The Home screen behind the dialog has tabs of its own: only the dialog's are read.
let nodes = out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default();
let by_id: std::collections::HashMap<_, _> = nodes.iter().map(|(id, n)| (*id, n)).collect();
let mut stack: Vec<_> = nodes.iter().filter(|(_, n)| n.role() == Role::Dialog).map(|(id, _)| *id).collect();
let mut tabs = Vec::new();
while let Some(id) = stack.pop() {
if let Some(node) = by_id.get(&id) {
if let (Role::Tab, Some(label), Some(b)) = (node.role(), node.label(), node.bounds()) {
tabs.push((b.x0, label.to_owned()));
}
stack.extend(node.children().iter().copied());
}
}
tabs.sort_by(|a, b| a.0.total_cmp(&b.0));
let order: Vec<&str> = tabs.iter().map(|(_, label)| label.as_str()).collect();
assert!(order.len() > 2, "the dialog's tabs: {order:?}");
assert_eq!(order[..2], ["Recent", "Saved"], "Saved follows Recent: {order:?}");
}
#[test]
fn a_preset_fills_the_details_and_create_makes_the_document() {
let mut app = app();