From 11caa7f82cb134ee64d9777441c8affd65a40c78 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Thu, 19 Nov 2026 09:58:21 -0500 Subject: [PATCH] App red round 6 g2: fixes from the g2 fixer --- crates/ui-egui/src/app.rs | 2 +- crates/ui-egui/src/app/commands.rs | 18 ++++++--- crates/ui-egui/src/app/reload.rs | 14 +++---- crates/ui-egui/src/canvas.rs | 6 +++ crates/ui-egui/src/canvas/page_tools.rs | 2 +- crates/ui-egui/src/commands.rs | 11 ++++-- crates/ui-egui/src/dialogs/host.rs | 1 + crates/ui-egui/src/panels/side_panels.rs | 5 +++ crates/ui-egui/src/tools/comments.rs | 2 +- crates/ui-egui/src/tools/comments/state.rs | 3 ++ crates/ui-egui/src/tools/comments/tool.rs | 44 +++++++++++++++++++--- crates/ui-egui/tests/it/actions.rs | 3 +- crates/ui-egui/tests/it/compare.rs | 2 +- crates/ui-egui/tests/it/forms.rs | 1 + crates/ui-egui/tests/it/preferences.rs | 11 +++++- crates/ui-egui/tests/it/recovery.rs | 4 +- crates/ui-egui/tests/it/reload.rs | 4 +- crates/ui-egui/tests/it/trust_signer.rs | 7 +++- crates/ui-egui/tests/page_shadows.rs | 3 ++ 19 files changed, 108 insertions(+), 35 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 71a8bb1280..058a51d590 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -70,7 +70,7 @@ impl AppServices { update_source, intake, #[cfg(not(target_arch = "wasm32"))] - watch, + watch: reload::document_watch(watch), } } diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index ab2a141606..c81137aab0 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -175,23 +175,29 @@ impl PdfCraftApp { /// keeps comment tools from reopening it; opening it again lets them (#225). A choice made in /// Read mode replaces the pane saved on the way in, so leaving Read mode doesn't undo it. pub fn choose_right_panel(&mut self, panel: Option) { + self.right_panel_chosen(self.right(), panel); + self.set_right(panel); + if let Some(panel) = panel { + self.last_right = panel; + } + } + + /// What the user's choice of the right panel, from `before` to `panel`, is remembered as: here + /// or in the dock (its tabs and Close button). + pub(crate) fn right_panel_chosen(&mut self, before: Option, panel: Option) { if self.mode == Mode::Read { self.right_before_read = None; } if panel == Some(RightPanel::Comments) { self.comments_panel_closed = false; - } else if panel.is_none() && self.right() == Some(RightPanel::Comments) { + } else if panel.is_none() && before == Some(RightPanel::Comments) { self.comments_panel_closed = true; } if panel.is_some() { self.right_panel_closed = false; - } else if self.right().is_some() { + } else if before.is_some() { self.right_panel_closed = true; } - self.set_right(panel); - if let Some(panel) = panel { - self.last_right = panel; - } } /// F4: closes the side panel, or reopens the one open last. diff --git a/crates/ui-egui/src/app/reload.rs b/crates/ui-egui/src/app/reload.rs index 4e451c3bd3..7f7ace861c 100644 --- a/crates/ui-egui/src/app/reload.rs +++ b/crates/ui-egui/src/app/reload.rs @@ -10,7 +10,6 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; -use craft::host::Wake; use craft::platform::watch::{Changed, FileStamp, FileWatch, ReadPolicy}; use pdfcraft_engine::DocId; @@ -20,12 +19,11 @@ use crate::PdfCraftApp; /// still being written then costs one small read. const TAIL: usize = 1024; -/// The watch of the open documents' files: a changed file is read whole once its last KiB holds -/// `%%EOF`. `wake` runs on the watch's worker when it finds a change; call `.inline()` on the -/// result for a watch that looks only when ticked (tests). -// PLAN: the app's `new(ctx)` and the tests' `AppServices` (pdf-hub-w1, L-183) build the watch they carry with this, so the read rule lives in one place -pub(crate) fn document_watch(wake: Wake) -> FileWatch { - FileWatch::new(wake).read(ReadPolicy::Whole { tail: TAIL, complete: Arc::new(|end: &[u8]| end.windows(5).any(|w| w == b"%%EOF")) }) +/// `watch` as the open documents' files are watched: a changed file is read whole once its last +/// KiB holds `%%EOF`. `AppServices::new` applies it to the watch it is given, the system's or a +/// test's, so the read rule lives in one place. +pub(crate) fn document_watch(watch: FileWatch) -> FileWatch { + watch.read(ReadPolicy::Whole { tail: TAIL, complete: Arc::new(|end: &[u8]| end.windows(5).any(|w| w == b"%%EOF")) }) } impl PdfCraftApp { @@ -221,7 +219,7 @@ mod tests { let (intake, _) = craft::platform::open::FileIntake::new(Wake::none()); let clipboard = craft::platform::clipboard::Clipboard::new(craft::platform::clipboard::EventClipboard::new(|| 0, |_| Ok(0))); // PLAN: assumed `AppServices::new(wake, clipboard, recovery_dir, update_source, intake, watch)` (L-207, pdf-hub-w1) - let services = crate::AppServices::new(Wake::none(), clipboard, None, None, intake, document_watch(Wake::none()).inline()); + let services = crate::AppServices::new(Wake::none(), clipboard, None, None, intake, FileWatch::new(Wake::none()).inline()); let path = path.to_owned(); let h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |cc| { crate::PdfCraftApp::install_runtime(&cc.egui_ctx); diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index f91ff3bdc4..729e9529c2 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1082,6 +1082,12 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession, let mut tool = page_tool(cx.chosen, tool_cx, &mut *session, &mut bench, &mut fill, &pass.press); let reply = ToolHost::new().momentary(momentary).run(ui, pass, &mut tool); let mut finish = tool.finish(); + // The comment gestures the run finished: each committed one is an engine edit, one undo step per drag. + let map = comments::PageMap::new(cx.info, body.pages, cx.rotation); + let now = ui.input(|i| i.time); + if let Some(edit) = comments::take_edits(&mut session.comments, &map, cx.info, cx.prefs, now) { + session.pending_edit = Some(edit); + } finish.apply(fill, session, &tool_cx); if let Some(why) = finish.refused.take() { session.objects.notice = Some(why.into()); diff --git a/crates/ui-egui/src/canvas/page_tools.rs b/crates/ui-egui/src/canvas/page_tools.rs index 831c5dbb3b..25cde72122 100644 --- a/crates/ui-egui/src/canvas/page_tools.rs +++ b/crates/ui-egui/src/canvas/page_tools.rs @@ -311,7 +311,7 @@ pub(crate) fn page_tool<'a>( let snap = caret_snap(tool, &cx, &session.texts, session.comments.tool.page); let view = &mut session.comments; let map = comments::PageMap::new(cx.info, cx.pages, cx.rotation); - let annotate = CommentsTool::new(&mut view.tool, &mut view.paste, map, &mut view.tool_done) + let annotate = CommentsTool::new(&mut view.tool, &mut view.paste, map, &mut view.tool_done, &mut view.tool_pressed) .settings(tool, cx.comment_prefs, cx.allowed, cx.doc.comments_hidden()) .outcome(&mut session.pending_edit, &mut view.notice); let annotate = match snap { diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs index 7ceb2c19b8..64f621af63 100644 --- a/crates/ui-egui/src/commands.rs +++ b/crates/ui-egui/src/commands.rs @@ -313,11 +313,14 @@ impl PdfCraftApp { "file.save_as" => { self.save_active(ctx, SaveTarget::As); } - "file.close" => { - if let Some(i) = active { - self.request_close_tab(ctx, i); + "file.close" => match active { + Some(i) => self.request_close_tab(ctx, i), + // macOS ⌘W closes the window when no document is open (#869), through the quit guard. + None if crate::commands::mac_shortcuts(ctx) && !cfg!(target_arch = "wasm32") => { + self.request_quit(ctx); } - } + None => {} + }, "file.close_all" => self.close_all(ctx), // PLAN: assumed the dialog openers are `PdfCraftApp` methods named as the sheet gives them (dialogs A-3..A-10), taking no argument unless the sheet names one. "file.revert" => self.ask_revert(), diff --git a/crates/ui-egui/src/dialogs/host.rs b/crates/ui-egui/src/dialogs/host.rs index c483645ac9..2e346c5339 100644 --- a/crates/ui-egui/src/dialogs/host.rs +++ b/crates/ui-egui/src/dialogs/host.rs @@ -38,6 +38,7 @@ pub(crate) fn open_over(app: &mut PdfCraftApp, dialog: D) -> Dia fn windows(app: &mut PdfCraftApp, ui: &mut egui::Ui) { app.show_preferences(ui); app.show_shortcuts(ui); + app.password_pass(ui); crate::workflows::js_dialogs::show(app, ui); crate::redact_ui::dialogs::show_props(app, ui); crate::redact_ui::dialogs::show_search(app, ui); diff --git a/crates/ui-egui/src/panels/side_panels.rs b/crates/ui-egui/src/panels/side_panels.rs index 54aeb264ff..b905990673 100644 --- a/crates/ui-egui/src/panels/side_panels.rs +++ b/crates/ui-egui/src/panels/side_panels.rs @@ -444,10 +444,15 @@ pub fn dock(app: &mut PdfCraftApp, ui: &mut Ui) { let output = DockArea::new("Dock", Bind::given(workspace), &mut panels, DockConfig::default().native_windows(false)) .hide(HidePanels::Except(&shown)) .show(ui); + let before = right_of(&app.dock); for action in output.actions.into_iter().chain(output.requested) { // The area drops what the workspace refuses; one refused here is stale, not the user's mistake. drop(app.dock.apply(action, false, permissions)); } + let after = right_of(&app.dock); + if after != before { + app.right_panel_chosen(before, after); + } if let Some(panel) = open_side(&app.dock).and_then(PanelId::side) { app.last_right = panel; } diff --git a/crates/ui-egui/src/tools/comments.rs b/crates/ui-egui/src/tools/comments.rs index c2c49feff4..0fd14f84a4 100644 --- a/crates/ui-egui/src/tools/comments.rs +++ b/crates/ui-egui/src/tools/comments.rs @@ -58,7 +58,7 @@ pub(crate) use state::PageCx; use state::after_delete; use state::login_name; pub use state::{CommentView, Composer, ComposerKind}; -pub(crate) use tool::{CommentsTool, PastePlacement, context_target, page_after_text, part_pressed}; +pub(crate) use tool::{CommentsTool, PastePlacement, context_target, page_after_text, part_pressed, take_edits}; /// Maximum stroke thickness offered by commenting controls, in PDF points. pub const MAX_LINE_WIDTH: f64 = 100.0; diff --git a/crates/ui-egui/src/tools/comments/state.rs b/crates/ui-egui/src/tools/comments/state.rs index c532d747da..6a96adc5a2 100644 --- a/crates/ui-egui/src/tools/comments/state.rs +++ b/crates/ui-egui/src/tools/comments/state.rs @@ -164,6 +164,9 @@ pub struct CommentView { pub context_at: Option<(usize, [f64; 2])>, /// A one-shot tool just finished; the app returns to the Select tool unless pinned. pub tool_done: bool, + /// The annotation tool took the open press (it did not answer `Ignored`): the drag, release and cancel are its, + /// not the text selection's. + pub(crate) tool_pressed: bool, /// Snapshot of `(page, index)` comment slot identity from the last `DocInfo`, used to detect /// when an edit removes or shifts `/Annots` entries under an active selection or editor. pub(crate) slots: std::collections::HashMap<(usize, usize), CommentSlot>, diff --git a/crates/ui-egui/src/tools/comments/tool.rs b/crates/ui-egui/src/tools/comments/tool.rs index 32c7930b51..f0702c17ed 100644 --- a/crates/ui-egui/src/tools/comments/tool.rs +++ b/crates/ui-egui/src/tools/comments/tool.rs @@ -45,6 +45,7 @@ pub(crate) struct CommentsTool<'a> { notice: Option<&'a mut Option<&'static str>>, map: PageMap<'a>, done: &'a mut bool, + pressed: &'a mut bool, quick: QuickTool, prefs: Option<&'a CommentPrefs>, allowed: bool, @@ -54,8 +55,15 @@ pub(crate) struct CommentsTool<'a> { impl<'a> CommentsTool<'a> { /// The tool over `annotate` (kept in `CommentView::tool`, so a gesture lasts across passes), the paste slot, the - /// pages on screen and the flag Escape sets when it leaves the tool (`CommentView::tool_done`). - pub(crate) fn new(annotate: &'a mut AnnotateTool, paste: &'a mut Option, map: PageMap<'a>, done: &'a mut bool) -> Self { + /// pages on screen, the flag Escape sets when it leaves the tool (`CommentView::tool_done`) and whether the + /// annotation tool took the open press (`CommentView::tool_pressed`, kept across passes with the gesture). + pub(crate) fn new( + annotate: &'a mut AnnotateTool, + paste: &'a mut Option, + map: PageMap<'a>, + done: &'a mut bool, + pressed: &'a mut bool, + ) -> Self { CommentsTool { annotate, text: None, @@ -64,6 +72,7 @@ impl<'a> CommentsTool<'a> { notice: None, map, done, + pressed, quick: QuickTool::Select, prefs: None, allowed: false, @@ -103,9 +112,10 @@ impl<'a> CommentsTool<'a> { self.map.page_at(Point::new(f64::from(at.x), f64::from(at.y))) } - /// Whether the annotation tool holds a gesture: the drag, release and cancel are its, else the text's. + /// Whether the annotation tool holds the gesture, as it took the press or is clicking out a shape: the drag, + /// release and cancel are its, else the text's. fn annotating(&self) -> bool { - self.annotate.in_flight().is_some() || !self.annotate.drawing().is_empty() + *self.pressed || !self.annotate.drawing().is_empty() } fn place(&mut self, page: usize, at: Pos2) { @@ -204,6 +214,7 @@ impl CanvasTool for CommentsTool<'_> { } fn press(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) -> ToolAction { + *self.pressed = false; if self.paste.is_some() { // A click places the bundle, centred where it is clicked, on the page under it; a right-click lets it // go. Nothing else on the page takes the press. @@ -216,7 +227,28 @@ impl CanvasTool for CommentsTool<'_> { } return ToolAction::Done; } - match self.annotate.press(pointer, cx) { + // A markup tool or Replace Text marks the text its drag selects (`page_after_text`): the text takes the press + // first. Under Select the comments come first, and a press no comment takes goes on to the text. + if matches!(self.quick, QuickTool::Comment(_)) + && let Some(text) = self.text.as_mut() + { + let action = text.press(pointer, cx); + if action != ToolAction::Ignored { + return action; + } + } + let action = self.annotate.press(pointer, cx); + *self.pressed = action != ToolAction::Ignored; + // A press on no comment passes through to the text (`EmptyPress::PassThrough`): it leaves the comments + // selected only while Shift or Cmd adds to the selection. + if action == ToolAction::Ignored + && self.annotate.tool == AnnotationTool::Select + && pointer.button == PointerButton::Primary + && !(pointer.mods.shift || pointer.mods.cmd) + { + self.annotate.selected.clear(); + } + match action { ToolAction::Ignored => match self.text.as_mut() { Some(text) => text.press(pointer, cx), None => ToolAction::Ignored, @@ -239,6 +271,7 @@ impl CanvasTool for CommentsTool<'_> { } else if let Some(text) = self.text.as_mut() { text.release(pointer, cx); } + *self.pressed = false; } fn hover(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) { @@ -254,6 +287,7 @@ impl CanvasTool for CommentsTool<'_> { } else if let Some(text) = self.text.as_mut() { text.cancel(reason, cx); } + *self.pressed = false; } fn claims(&self) -> ToolClaims { diff --git a/crates/ui-egui/tests/it/actions.rs b/crates/ui-egui/tests/it/actions.rs index 19f611d960..1567cb72cf 100644 --- a/crates/ui-egui/tests/it/actions.rs +++ b/crates/ui-egui/tests/it/actions.rs @@ -46,7 +46,8 @@ fn run_and_create_actions() { assert!(h.execute("actions.distribution")); h.run_steps(2); h.get_by_role_and_label(Role::Dialog, "Action Wizard"); - h.get_by_label("1. Remove hidden information"); + // The chosen action's description lists its numbered steps, one per line. + h.get_by_label_contains("1. Remove hidden information"); h.get_by_label("Start").click(); finish(&mut h, &jobs); assert_eq!(support::shown_notice(&h).as_deref(), Some("Prepare for Distribution: 1 file done")); diff --git a/crates/ui-egui/tests/it/compare.rs b/crates/ui-egui/tests/it/compare.rs index c9f4b7c4f7..81d79109ac 100644 --- a/crates/ui-egui/tests/it/compare.rs +++ b/crates/ui-egui/tests/it/compare.rs @@ -25,7 +25,7 @@ fn compare_two_versions() { h.run_steps(4); assert!(h.execute("doc.compare")); h.run_steps(2); - h.get_by_label("Compare Files"); + h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Compare Files"); h.get_by_label("Compare").click(); h.run_steps(3); assert_eq!(crate::support::right(h.state()), Some(RightPanel::Compare)); diff --git a/crates/ui-egui/tests/it/forms.rs b/crates/ui-egui/tests/it/forms.rs index 7fba4644ea..8a0489886f 100644 --- a/crates/ui-egui/tests/it/forms.rs +++ b/crates/ui-egui/tests/it/forms.rs @@ -1382,6 +1382,7 @@ mod revert_tests { // A document with no file asks where to save: the scripted answer arrives on a later pass. h.state_mut().save_active(&ctx_h, pdfcraft_ui_egui::SaveTarget::InPlace); crate::support::wait_until(&mut h, "the save", |s| s.views.first().and_then(|v| s.session.get(v.id)).is_some_and(|d| !d.dirty)); + wait_for_file(&mut h, &path); let saved = std::fs::read(&path).unwrap(); let ctx_h = h.ctx.clone(); assert!(h.state_mut().apply_edit( diff --git a/crates/ui-egui/tests/it/preferences.rs b/crates/ui-egui/tests/it/preferences.rs index 9469bd494e..71369262b8 100644 --- a/crates/ui-egui/tests/it/preferences.rs +++ b/crates/ui-egui/tests/it/preferences.rs @@ -61,7 +61,16 @@ fn type_into(h: &mut H, label: &str, text: &str) { fn cases() -> Vec { vec![ - Case { name: "default mode", page: "Documents and view", edit: |h| click(h, "E-Sign"), applied: |a| a.default_mode == Mode::Sign }, + Case { + name: "default mode", + page: "Documents and view", + edit: |h| { + // A choice row is a drop-down: its options show once it opens. + click(h, "Default workspace mode"); + click(h, "E-Sign"); + }, + applied: |a| a.default_mode == Mode::Sign, + }, Case { name: "layout and continuous on the active view", page: "Documents and view", diff --git a/crates/ui-egui/tests/it/recovery.rs b/crates/ui-egui/tests/it/recovery.rs index 7f98e5024f..ebc68f7fe4 100644 --- a/crates/ui-egui/tests/it/recovery.rs +++ b/crates/ui-egui/tests/it/recovery.rs @@ -293,12 +293,12 @@ fn encrypted(bytes: Vec, password: &str) -> Vec { fn type_password(h: &mut Harness<'static, PdfCraftApp>, password: &str) { // The prompt is laid out in the pass after the one that set it. for _ in 0..10 { - if h.query_by_role(Role::PasswordInput).is_some() { + if h.query_by_role_and_label(Role::PasswordInput, "Password").is_some() { break; } h.run_steps(1); } - let field = h.get_by_role(Role::PasswordInput); + let field = h.get_by_role_and_label(Role::PasswordInput, "Password"); field.focus(); field.type_text(password); h.run_steps(2); diff --git a/crates/ui-egui/tests/it/reload.rs b/crates/ui-egui/tests/it/reload.rs index 4d6cacfc91..547d4d8e01 100644 --- a/crates/ui-egui/tests/it/reload.rs +++ b/crates/ui-egui/tests/it/reload.rs @@ -350,7 +350,7 @@ fn saving_over_a_file_changed_by_something_else_asks_first() { let ctx_h = h.ctx.clone(); assert!(!h.state_mut().save_active(&ctx_h, SaveTarget::InPlace), "not written yet"); h.run_steps(2); - h.get_by_label("File changed"); + h.get_by_role_and_label(egui::accesskit::Role::Dialog, "File changed"); h.get_by_label("Cancel").click(); h.run_steps(2); assert_eq!(std::fs::read(&file.path).unwrap(), fixture(4), "Cancel keeps the newer file"); @@ -381,7 +381,7 @@ fn saving_checks_the_file_with_the_watcher_off_too() { let ctx_h = h.ctx.clone(); assert!(!h.state_mut().save_active(&ctx_h, SaveTarget::InPlace)); h.run_steps(2); - h.get_by_label("File changed"); + h.get_by_role_and_label(egui::accesskit::Role::Dialog, "File changed"); } /// One file, one tab (#2166): opening a file that is open already brings its tab forward, diff --git a/crates/ui-egui/tests/it/trust_signer.rs b/crates/ui-egui/tests/it/trust_signer.rs index 2048c8fbea..fa4a20ab85 100644 --- a/crates/ui-egui/tests/it/trust_signer.rs +++ b/crates/ui-egui/tests/it/trust_signer.rs @@ -6,7 +6,7 @@ use crate::support; use crate::support::AppHarness as _; use egui_kittest::Harness; -use egui_kittest::kittest::Queryable; +use egui_kittest::kittest::{NodeT, Queryable}; use pdfcraft_engine::SignatureStatus; use pdfcraft_ui_egui::{PdfCraftApp, SignStep}; @@ -81,7 +81,10 @@ fn one_click_trust_stores_the_displayed_signer_not_the_embedded_root() { }; // Open the signature row (a click picks it, Right opens a tree row) and use the one-click trust button. - h.get_by_label_contains("Signed by").click(); + h.query_all_by(|n| n.role() == egui::accesskit::Role::TreeItem && n.label().is_some_and(|l| l.contains("Signed by"))) + .next() + .expect("the signature's row") + .click(); h.run_steps(1); h.key_press(egui::Key::ArrowRight); h.run_steps(2); diff --git a/crates/ui-egui/tests/page_shadows.rs b/crates/ui-egui/tests/page_shadows.rs index 3bdcb7259e..fe2219ff1c 100644 --- a/crates/ui-egui/tests/page_shadows.rs +++ b/crates/ui-egui/tests/page_shadows.rs @@ -68,6 +68,9 @@ fn checkbox_and_multiple_documents_do_not_edit_pdf_state() { h.set_option("dialog", "preferences").unwrap(); h.run_steps(3); assert_eq!(h.state().settings_snapshot().behavior.show_page_edge_shadows, Some(true)); + // Preferences shows one page at a time; the shadows are on Appearance. + h.get_by_label("Appearance").click(); + h.run_steps(3); let checkbox = h.get_by_label("Show Page Edge Shadows"); checkbox.click(); h.run_steps(2);