From 8ff4285ea212d57597bc922cbdce685e720a375e Mon Sep 17 00:00:00 2001 From: Madhav Agarwal Date: Sun, 29 Nov 2026 11:29:34 +0530 Subject: [PATCH] fix(ui): name a warning found after an edit on a dismissed page (#4340) page_changed drops the page's cached render warnings but kept the reader's dismissal for that page, so a different warning found after the edit stayed hidden behind the old dismissal. Forget the dismissal with the reports. The notice bar's icon call moves to the IconId type from main. --- crates/ui-egui/src/canvas/bars.rs | 2 +- crates/ui-egui/src/canvas/cache.rs | 3 +++ crates/ui-egui/src/canvas/tests.rs | 33 ++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas/bars.rs b/crates/ui-egui/src/canvas/bars.rs index 556058553d..cc686c1b20 100644 --- a/crates/ui-egui/src/canvas/bars.rs +++ b/crates/ui-egui/src/canvas/bars.rs @@ -323,7 +323,7 @@ fn warned_pages_bar(view: &mut DocView, ui: &mut egui::Ui) { &[("n", &n.to_string()), ("page", &page), ("what", &what)], ) }; - if bar(Tone::Warn, "triangle-alert", text).dismiss().show(ui).dismissed { + if bar(Tone::Warn, IconId::new("triangle-alert"), text).dismiss().show(ui).dismissed { view.warn_notice_dismissed.extend(warned.iter().map(|(page, _)| *page)); } } diff --git a/crates/ui-egui/src/canvas/cache.rs b/crates/ui-egui/src/canvas/cache.rs index af69f17a63..6c2a3f2a98 100644 --- a/crates/ui-egui/src/canvas/cache.rs +++ b/crates/ui-egui/src/canvas/cache.rs @@ -81,6 +81,9 @@ impl DocView { let _dropped = queue.reprioritize(|key, priority| (*key != page).then_some(priority)); } self.reports.forget(page); + // The page's old warnings are gone, so a reader's dismissal of them no longer covers the + // page: a warning found after the edit must be named, not stay hidden (#4340 review). + self.warn_notice_dismissed.remove(&page); if self.session.text.selection.as_ref().is_some_and(|s| s.pages().contains(&page)) { // With the marks a tool waits to make on it (#5017 review). self.session.text.selection = None; diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 54393eaa3e..aa78dfc14a 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -317,6 +317,39 @@ fn a_page_with_a_render_warning_is_named_until_dismissed() { h.get_by_label_contains("spaced by their procedures"); } +/// An edit drops that page's cached warnings together with the reader's dismissal of them: a +/// different warning found after the edit is named, though the page's old one was dismissed +/// (#4340 review). +#[test] +fn a_warning_after_an_edit_on_a_dismissed_page_is_named() { + use egui_kittest::kittest::Queryable; + use pdfcraft_render::RenderWarning; + + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 900.0)).build_eframe(|cc| { + crate::PdfCraftApp::install_runtime(&cc.egui_ctx); + { + let mut app = PdfCraftApp::for_unit_tests(); + app.set_option(&cc.egui_ctx, "language", "en").unwrap(); + let bytes = app.session.create_blank(300.0, 400.0, 2).unwrap(); + app.open_bytes(&egui::Context::default(), "blank.pdf", None, bytes.as_ref().clone()).unwrap(); + app + } + }); + h.run_steps(3); + h.state_mut().views[0].reports.warn(0, RenderWarning::ColourFallback); + h.run_steps(2); + h.get_by_label_contains("painted in a fallback colour"); + h.get_by_label("Dismiss").click(); + h.run_steps(2); + assert!(h.query_by_label_contains("painted in a fallback colour").is_none(), "the warning bar can be dismissed"); + // The page is edited, so the renderer finds a different warning on it: the old dismissal + // covered the warning that is gone, not this one. + h.state_mut().views[0].page_changed(0); + h.state_mut().views[0].reports.warn(0, RenderWarning::Type3WidthsMissing); + h.run_steps(2); + h.get_by_label_contains("spaced by their procedures"); +} + /// Dismissing another notice doesn't hide a page found cut later (#623), and dismissing the /// cut-page notice lasts until another page is found cut (review on #2113). #[test]