diff --git a/crates/ui-egui/src/tools/camera_ui.rs b/crates/ui-egui/src/tools/camera_ui.rs index ce88da25cf..f2e07fab35 100644 --- a/crates/ui-egui/src/tools/camera_ui.rs +++ b/crates/ui-egui/src/tools/camera_ui.rs @@ -98,9 +98,12 @@ pub(crate) fn page_input(resp: &egui::Response, xf: &PageXform, ptr: &PagePointe if view.camera.is_none() && page == view.current { view.camera = Some(CameraQuad::inset(page, xf.pw, xf.ph)); } + // A press nobody holds on a page without the quadrilateral moves it there: a drag from where it + // began, a click where it came up (egui has cleared the press's origin by its release). + let at = if resp.clicked() { pointer } else { origin }; if (resp.drag_started() || resp.clicked()) && press == PagePress::Free - && origin.is_some_and(|o| xf.rect.contains(o)) + && at.is_some_and(|p| xf.rect.contains(p)) && view.camera.is_none_or(|q| q.page != page) { view.camera = Some(CameraQuad::inset(page, xf.pw, xf.ph)); diff --git a/crates/ui-egui/tests/it/pointer.rs b/crates/ui-egui/tests/it/pointer.rs index 8364f3a635..2fc79d1f63 100644 --- a/crates/ui-egui/tests/it/pointer.rs +++ b/crates/ui-egui/tests/it/pointer.rs @@ -1725,3 +1725,17 @@ fn a_right_click_between_the_pages_anchors_no_pages_menu() { right_click(&mut h, gap); assert_eq!(h.state().views[0].comments.context_at, None); } + +/// With the camera tool, a click on another page moves the quadrilateral there, as a drag from it +/// does. The click was located by its press's origin, which egui has cleared by the release frame, +/// so it did nothing (on `main` too). +#[test] +fn a_camera_click_on_another_page_moves_the_quadrilateral_there() { + let mut h = open(two_pages_pdf(), "100", false); + h.state_mut().quick_tool = QuickTool::EnhanceCamera; + h.run_steps(4); + assert_eq!(h.state().views[0].camera.map(|q| q.page), Some(0), "it starts on the current page"); + let two = h.state().views[0].page_screen_rect(1).expect("page 2 on screen"); + mouse_click(&mut h, two.min + egui::vec2(100.0, 60.0)); + assert_eq!(h.state().views[0].camera.map(|q| q.page), Some(1)); +}