fix(ui): a camera click on another page moves the quadrilateral there

Found in review (CodeRabbit): with the camera tool, a press nobody holds on a page without the
quadrilateral moves it there, but a click was located by its press's origin, which egui has
cleared by the release frame. So only a drag moved it, and a click did nothing. This was so on
`main` too. A click is now located where it came up; `PagePress::Free` already says its press
began on this page.

Test: `a_camera_click_on_another_page_moves_the_quadrilateral_there`, seen failing without the
fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
alehelandClaude Opus 5.5 committed 2026-11-02 21:51:52 +01:00
1 parent 58bb5ba3d0
commit b77903012d
2 files changed
+18 -1

No files matched your search

+4 -1
View File
@@ -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));
+14
View File
@@ -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));
}