PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Leave the page grid when the Crop tool is chosen
eliets264d8c20584f2
diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rsindex 92bc0b360..f908cd423 100644--- a/crates/ui-egui/src/commands.rs+++ b/crates/ui-egui/src/commands.rs@@ -669,6 +669,9 @@ impl PdfCraftApp {}"page.crop" => {self.quick_tool = crate::QuickTool::Crop;+ if let Some(v) = active.and_then(|i| self.views.get_mut(i)) {+ v.organize = false;+ }self.notify_tr("Drag a rectangle on a page to crop it; double-click a page for Set Page Boxes");}"page.boxes" => {diff --git a/crates/ui-egui/tests/it/pageboxes.rs b/crates/ui-egui/tests/it/pageboxes.rsindex 865f12770..2e2829e05 100644--- a/crates/ui-egui/tests/it/pageboxes.rs+++ b/crates/ui-egui/tests/it/pageboxes.rs@@ -90,3 +90,32 @@ fn duplicate_pages_copies_the_current_page() {let s = h.state();assert_eq!(s.session.get(s.views[0].id).unwrap().info.pages.len(), 3);}++#[test]+fn the_crop_tool_leaves_the_page_grid_so_a_page_can_be_cropped() {+ let mut h = harness();+ // The Organize panel's thumbnail grid is on screen for this view: choosing+ // "Crop pages" from it must leave the grid so the canvas handles a drag on+ // a page instead of returning early to organize_grid.+ h.state_mut().views[0].organize = true;+ assert!(h.state_mut().execute("page.crop"));+ assert_eq!(h.state().quick_tool, QuickTool::Crop);+ assert!(!h.state().views[0].organize, "\"page.crop\" must clear view.organize");+ h.run_steps(2);+ let r = h.state().views[0].page_screen_rect(0).unwrap();+ // The middle half of the page in both directions.+ let (a, b) = (r.min + r.size() * 0.25, r.min + r.size() * 0.75);+ h.hover_at(a);+ h.run_steps(1);+ h.drag_at(a);+ h.run_steps(1);+ for k in 1..=4 {+ h.hover_at(a + (b - a) * (k as f32 / 4.0));+ h.run_steps(1);+ }+ h.drop_at(b);+ h.run_steps(4);+ let (w, hh) = size(&h, 0);+ assert!((w - 150.0).abs() < 2.0 && (hh - 200.0).abs() < 2.0, "{w}×{hh}");+ assert_eq!(size(&h, 1), (300.0, 400.0));+}