diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 51f33bb4f5..2256a8942c 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1270,8 +1270,7 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu organize_grid(&mut app.views[index], doc, &mut organize::GridCx { ui, session: &app.session, zoom: &mut app.organize_zoom, invert_middle }); return None; } - // The room under the notice bars, inside the rect the caller gave. - let rect = rect.intersect(ui.available_rect_before_wrap()); + // The room under the notice bars, inside the rect the caller gave. let rect = rect.intersect(ui.available_rect_before_wrap()); let preparing = app.is_preparing(); // PLAN: assumed `side_panels::panel_visible(app, panel) -> bool` for the left panel's visibility (`left_open` is diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index ae66ce0511..277311fff2 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -30,11 +30,14 @@ pub(super) mod word_count_ui; pub(crate) use prompts::shorten_middle; pub(crate) use properties::PropsTab; -/// Drop (and zeroize) the Sign password draft. Sign is a window beside the dialog host, so opening any dialog ends -/// it: `host::open` and `host::open_over`, commands and control requests call this, since a close and a reopen can -/// happen between frames. The control paths that start signing call it before `start_signing`. +/// Drop (and zeroize) the Sign password draft once Sign is no longer the active window: Sign is a window beside the +/// dialog host, so any dialog open on the host ends it. `host::open` and `host::open_over` call this after opening, +/// and commands and control requests after they run, since a close and a reopen can happen between frames; a command +/// that starts signing opens no dialog, so its draft stays. pub(crate) fn discard_inactive_password_drafts(app: &mut PdfCraftApp) { - app.sign_draft = None; + if app.dialogs.stack().top().is_some() { + app.sign_draft = None; + } } /// Draws the dialogs over the window and acts on the answers they gave this pass. diff --git a/crates/ui-egui/src/dialogs/host.rs b/crates/ui-egui/src/dialogs/host.rs index ae7c47da0a..c483645ac9 100644 --- a/crates/ui-egui/src/dialogs/host.rs +++ b/crates/ui-egui/src/dialogs/host.rs @@ -19,17 +19,19 @@ pub(crate) fn run(app: &mut PdfCraftApp, ui: &mut egui::Ui) { /// Opens `dialog` on the host. Opening a dialog ends the Sign window's password draft. pub(crate) fn open(app: &mut PdfCraftApp, dialog: D) -> DialogId { + let id = app.dialogs.open(dialog); super::discard_inactive_password_drafts(app); - app.dialogs.open(dialog) + id } /// Opens `dialog` above the dialog on top of the stack, which stays open under it; with none open, as [`open`]. pub(crate) fn open_over(app: &mut PdfCraftApp, dialog: D) -> DialogId { - super::discard_inactive_password_drafts(app); - match app.dialogs.stack().top() { + let id = match app.dialogs.stack().top() { Some(parent) => app.dialogs.open_child(dialog, parent), None => app.dialogs.open(dialog), - } + }; + super::discard_inactive_password_drafts(app); + id } /// The windows the app keeps beside the host: movable, so the page under them stays in view. diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rs index 87872f1f82..9d34295f3d 100644 --- a/crates/ui-egui/src/home.rs +++ b/crates/ui-egui/src/home.rs @@ -213,6 +213,6 @@ mod tests { } }); h.run_steps(4); - assert_eq!(h.get_all_by_label(tl!(label)).count(), 1); + assert_eq!(h.get_all_by_role_and_label(egui::accesskit::Role::ListItem, tl!(label)).count(), 1, "one tile for the tool"); } } diff --git a/crates/ui-egui/src/panels/side_panels.rs b/crates/ui-egui/src/panels/side_panels.rs index 36b46fe891..2d4a4d4c8d 100644 --- a/crates/ui-egui/src/panels/side_panels.rs +++ b/crates/ui-egui/src/panels/side_panels.rs @@ -350,12 +350,6 @@ impl Panels<'_> { /// the page area. fn document_view(app: &mut PdfCraftApp, ui: &mut Ui, rect: egui::Rect) { app.settle_document_view(); - eprintln!( - "DIAG continuous_layout_stacks_pages_vertically: document_view rect={rect:?} avail={:?} max={:?} screen={:?}", - ui.available_rect_before_wrap(), - ui.max_rect(), - ui.ctx().content_rect() - ); if app.full_screen_document() { ui.painter().rect_filled(rect, 0.0, egui::Color32::BLACK); if let Some(i) = app.active { diff --git a/crates/ui-egui/src/workflows/create_ui.rs b/crates/ui-egui/src/workflows/create_ui.rs index 026d5b9003..14713f92f0 100644 --- a/crates/ui-egui/src/workflows/create_ui.rs +++ b/crates/ui-egui/src/workflows/create_ui.rs @@ -475,9 +475,18 @@ mod tests { let files = Arc::new(ScriptedFiles::held()); let jobs = Arc::new(ManualJobs::new()); let mut h = reducing(files.clone(), jobs.clone(), text_pdf("Minutes of the harbour board")); + // The page's own work (its pictures and text) settles first, so the queue below holds only the reduction's. + while jobs.run_all() > 0 { + h.run_steps(2); + } let ctx_h = h.ctx.clone(); h.state_mut().reduce_file_size(&ctx_h); h.run_steps(2); + eprintln!( + "DIAG reduce_file_size_asks_where_to_save_before_it_compresses: run {} waiting {}", + h.state().optimize_run.is_some(), + jobs.waiting() + ); assert!(h.state().optimize_run.is_none() && jobs.waiting() == 0, "nothing runs until the answer is in"); assert_eq!(files.open(), 1, "the question is out"); assert!(files.file(&out).is_none(), "no copy is written before the answer"); diff --git a/crates/ui-egui/src/workflows/ocr_ui.rs b/crates/ui-egui/src/workflows/ocr_ui.rs index b2ee29bfc2..4fc52a2bde 100644 --- a/crates/ui-egui/src/workflows/ocr_ui.rs +++ b/crates/ui-egui/src/workflows/ocr_ui.rs @@ -1238,6 +1238,8 @@ mod tests { for id in ids { app.dialogs.cancel_by_id(&ctx, id); } + // The JavaScript console is a window beside the host; closing it drops it. + app.js_dialog = None; } /// The text of the notices posted so far. diff --git a/crates/ui-egui/tests/it/actions.rs b/crates/ui-egui/tests/it/actions.rs index 6afc3ebd11..19f611d960 100644 --- a/crates/ui-egui/tests/it/actions.rs +++ b/crates/ui-egui/tests/it/actions.rs @@ -45,7 +45,7 @@ fn run_and_create_actions() { let mut h = harness(&files, &jobs); assert!(h.execute("actions.distribution")); h.run_steps(2); - h.get_by_label("Action Wizard"); + h.get_by_role_and_label(Role::Dialog, "Action Wizard"); h.get_by_label("1. Remove hidden information"); h.get_by_label("Start").click(); finish(&mut h, &jobs); diff --git a/crates/ui-egui/tests/it/layer_actions.rs b/crates/ui-egui/tests/it/layer_actions.rs index a0bf5a52f4..0284d4de92 100644 --- a/crates/ui-egui/tests/it/layer_actions.rs +++ b/crates/ui-egui/tests/it/layer_actions.rs @@ -150,7 +150,7 @@ fn the_layers_panel_shows_the_order_tree() { let mut h = harness_with(fixture_with("/Order [[(Colours) 5 0 R]]"), |app| app.set_option(&egui::Context::default(), "panel", "layers").unwrap()); h.run_steps(2); let label = h.get_by_role_and_label(Role::TreeItem, "Colours").rect(); - let red = h.get_by_label("Red").rect(); + let red = h.get_by_role_and_label(Role::TreeItem, "Red").rect(); assert!(red.min.y > label.max.y - 1.0, "Red is listed under its label"); assert!(h.query_by_label("Green").is_none(), "Green isn't in /Order, so it isn't presented"); assert_eq!(shown(&h), layers(true, false), "but it is still a layer, in its state"); diff --git a/crates/ui-egui/tests/it/open_action.rs b/crates/ui-egui/tests/it/open_action.rs index 2944f04d4e..03e2863288 100644 --- a/crates/ui-egui/tests/it/open_action.rs +++ b/crates/ui-egui/tests/it/open_action.rs @@ -163,7 +163,7 @@ fn a_full_screen_document_shows_its_non_full_screen_panel_outside_full_screen() for (mode, want) in [("UseThumbs", Some(RightPanel::Pages)), ("UseOC", Some(RightPanel::Layers)), ("UseNone", None)] { let mut h = harness(&format!("/PageMode /FullScreen /ViewerPreferences << /NonFullScreenPageMode /{mode} >>")); // The prompt (`ask_full_screen`) is on the dialog host, found by its question. - h.get_by_label("Open in Full Screen mode?"); + h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Open in Full Screen mode?"); assert_eq!(crate::support::right(h.state()), want, "{mode}: the panel behind the prompt"); // Declining it leaves that panel. h.get_by_label("Not now").click(); diff --git a/crates/ui-egui/tests/it/recent_files.rs b/crates/ui-egui/tests/it/recent_files.rs index 6acb61abd1..b7024f7dd7 100644 --- a/crates/ui-egui/tests/it/recent_files.rs +++ b/crates/ui-egui/tests/it/recent_files.rs @@ -89,7 +89,7 @@ fn at_zero_home_has_no_recent_section() { #[test] fn above_zero_an_empty_list_still_says_what_it_is_for() { let h = harness(1, &[]); - h.get_by_label("Recent"); + h.get_by_role_and_label(egui::accesskit::Role::Heading, "Recent"); h.get_by_label_contains("Files you open in PdfCraft appear here"); } diff --git a/crates/ui-egui/tests/it/signing.rs b/crates/ui-egui/tests/it/signing.rs index 2ce41dd234..b3a583d272 100644 --- a/crates/ui-egui/tests/it/signing.rs +++ b/crates/ui-egui/tests/it/signing.rs @@ -778,7 +778,7 @@ fn windows_store_identity_does_not_ask_for_a_file_password() { h.run_steps(3); h.get_by_label("Continue").click(); h.run_steps(3); - h.get_by_label("Sign as \"Store signer\""); + h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Sign as \"Store signer\""); assert_eq!(h.query_all_by_label("Digital ID password").count(), 0); h.get_by_label("The key is in the Windows certificate store, which may ask to allow PdfCraft to use it."); support::outside_menus(&h, "Sign").click();