pipe pointer-1: fixes for pointer (10 tests)

This commit is contained in:
Dylan M. Taylor committed 2026-11-20 03:45:31 -05:00
1 parent 98ad81cd65
commit 7ff13a0faf
6 files changed
+59 -19

No files matched your search

+17 -5
View File
@@ -969,7 +969,7 @@ fn page_parts_of(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSessi
if matches!(cx.tool, QuickTool::Select | QuickTool::Link) {
links_of(session, cx, body).parts(&mut parts);
}
if cx.tool == QuickTool::Select && !cx.comments_hidden {
if !cx.comments_hidden {
// The comment a press under the pointer would take, hit within the theme's reach and with its markers at the
// icon size, both as the tools on the canvas read them.
let env = Env::of(ui);
@@ -979,7 +979,11 @@ fn page_parts_of(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSessi
let on_link = ui
.input(|i| i.pointer.hover_pos())
.is_some_and(|p| parts.iter().any(|part| matches!(part.owner, Owner::Link { .. } | Owner::TextLink { .. }) && part.shape.hit(p)));
parts.extend(comments::parts(cx.info, &map, cx.prefs, cx.tool, pointer, &session.comments.tool, tolerance, icon_side, on_link));
if cx.tool == QuickTool::Select
|| cx.unobstructed && session.comments.tool.in_flight().is_none() && session.comments.tool.drawing().is_empty()
{
parts.extend(comments::parts(cx.info, &map, cx.prefs, cx.tool, pointer, &session.comments.tool, tolerance, icon_side, on_link));
}
}
// Fields take the page's presses under Select only: another tool's press over a field is the tool's (a new
// text box, a mark, a stamp).
@@ -1061,7 +1065,10 @@ fn route_press(
}
// A picture is selected for its menu only when the right-click lands on its visible body
// on the page; a right-click on its out-of-page frame or anything else lets it go.
let on_page = press.phase.start().is_some_and(|start| body.pages.iter().any(|p| p.page == press.page && p.rect.contains(start.origin)));
let on_page = press
.phase
.start()
.is_some_and(|start| body.pages.iter().find(|p| p.rect.contains(start.origin)).is_some_and(|p| p.page == press.page));
if !held {
let picture = match owner {
Owner::Picture { index } if on_page => Some(index),
@@ -1070,7 +1077,9 @@ fn route_press(
crate::edit_text_ui::picture_context(press.page, picture, session);
}
if matches!(owner, Owner::Picture { .. }) && !on_page {
session.menu_for = None;
if let Some(start) = press.phase.start() {
background_context(ui, session, cx, body, start.origin);
}
return;
}
}
@@ -1120,7 +1129,7 @@ fn route_press(
crate::prepare::tool::field_press(session, cx.form, press);
}
// A link reads its own right-click too: its context event selects it for the Link tool's menu.
if !matches!(press.owner, Owner::Link { .. } | Owner::TextLink { .. }) {
if !matches!(owner, Owner::Link { .. } | Owner::TextLink { .. }) || menu_for != Some((press.page, owner)) {
return;
}
}
@@ -1276,6 +1285,9 @@ fn page_before(ui: &mut egui::Ui, body: &PageBody<'_>, callbacks: &mut PageCallb
}
route_press(ui, session, press, &parts, cx, body, out);
}
if let Some(at) = parts_out.context {
background_context(ui, session, cx, body, at);
}
// Focus arrived on a field (Tab, a request or a click): the field opens, a text field with its text selected.
let field_arrived = match &parts_out.focused {
Some((owner @ Owner::Field { .. }, _)) => {
+12 -3
View File
@@ -136,6 +136,8 @@ pub(crate) enum PageLayer {
Comment,
/// Form fields' widgets and the sign tabs over them.
Field,
/// Movable comment bodies, above filled form fields and below added content.
MovableComment,
/// What a tool placed and moves: added content, Prepare's fields, the objects selected together.
Placed,
/// Handles on what is selected, and the frame band of the paragraph open for typing.
@@ -154,7 +156,8 @@ impl PageLayer {
PageLayer::Link => (HitLevel::Body, 3),
PageLayer::Comment => (HitLevel::Body, 4),
PageLayer::Field => (HitLevel::Body, 5),
PageLayer::Placed => (HitLevel::Body, 6),
PageLayer::MovableComment => (HitLevel::Body, 6),
PageLayer::Placed => (HitLevel::Body, 7),
PageLayer::Handle => (HitLevel::Handle, 0),
PageLayer::Editor => (HitLevel::Handle, 1),
};
@@ -312,6 +315,8 @@ pub(crate) struct PagePartsOutput {
pub(crate) response: Response,
/// The press on a part, in the phase this pass reports.
pub(crate) press: Option<PagePress>,
/// A secondary click beside an ongoing press on a part.
pub(crate) context: Option<egui::Pos2>,
/// A key the focused part was given: a form field's toggle, its arrows, Enter or typed text.
pub(crate) key: Option<(Owner, Intent)>,
/// Tab (`true`) or Shift+Tab (`false`) pressed while a focusable field part held focus.
@@ -347,6 +352,7 @@ pub(crate) struct PageParts<'a> {
#[derive(Debug, Default)]
struct Report {
press: Option<PagePress>,
context: Option<egui::Pos2>,
key: Option<(Owner, Intent)>,
tab: Option<(Owner, bool)>,
hovered: Option<(Owner, usize)>,
@@ -464,6 +470,9 @@ impl Component for PageParts<'_> {
let Some(at) = part.owner.part_ref(part.page) else { continue };
let Some(result) = cx.part_if_declared(at) else { continue };
let (press, hovered) = (result.press, result.hovered);
if self.report.context.is_none() {
self.report.context = press.context;
}
if hovered && self.report.hovered.is_none() {
self.report.hovered = Some((part.owner, part.page));
}
@@ -500,7 +509,7 @@ impl Component for PageParts<'_> {
}
fn finish(self, cx: Cx<'_, Self>) -> PagePartsOutput {
let Report { press, key, tab, hovered, focused } = self.report;
PagePartsOutput { response: cx.response.clone(), press, key, tab, hovered, focused }
let Report { press, context, key, tab, hovered, focused } = self.report;
PagePartsOutput { response: cx.response.clone(), press, context, key, tab, hovered, focused }
}
}
+9 -2
View File
@@ -411,7 +411,7 @@ pub(crate) fn parts(
let (Some(page), at) = (map.page_at(screen), ()) else { return Vec::new() };
let _ = at;
let Some(at) = map.to_page(page, screen) else { return Vec::new() };
let anns: Vec<Marked> = annotations(info, map, tool, true).into_iter().filter(|a| a.page == page).collect();
let anns: Vec<Marked> = annotations(info, map, QuickTool::Select, true).into_iter().filter(|a| a.page == page).collect();
let markers = marker_boxes(map, &anns, icon_side);
let Some(id) = pick_at(&anns, at, tolerance, icon_side, &markers) else { return Vec::new() };
let Some(found) = anns.iter().find(|a| a.id == id) else { return Vec::new() };
@@ -451,7 +451,14 @@ pub(crate) fn parts(
return vec![PagePart::new(owner, page, shape, PageLayer::Comment).context_only()];
}
let tip = tips(info, prefs, tool).into_iter().find(|(t, _)| *t == id).map(|(_, tip)| tip);
let layer = if engine(info, page, index).is_some_and(|a| a.fill_sign) { PageLayer::Placed } else { PageLayer::Comment };
let layer = if found.kind.is_markup() && !engine(info, page, index).is_some_and(|a| a.fill_sign) {
PageLayer::Comment
} else {
PageLayer::MovableComment
};
if tool != QuickTool::Select {
return tip.map(|tip| vec![PagePart::new(owner, page, shape, layer).hover_only().tip_now(tip)]).unwrap_or_default();
}
let part = PagePart::new(owner, page, shape, layer).passes_drag().cursor(icon);
vec![match tip {
Some(tip) => part.tip_now(tip),
+4 -2
View File
@@ -462,8 +462,10 @@ pub(crate) fn page_parts(
&& let Ok(objects) = session.objects.inventory(doc, page)
&& let Some(object) = objects.iter().find(|o| o.target == ObjectTarget { kind: ObjectKind::Text, index: block })
{
out.extend(frame_band(screen(&xf, info, page, object)).into_iter().enumerate().map(|(side, band)| {
PagePart::new(Owner::Frame { block, side }, page, HitShape::Rect(band), PageLayer::Handle).cursor(CursorIcon::Move)
out.extend(frame_band(screen(&xf, info, page, object)).into_iter().enumerate().filter_map(|(side, band)| {
let band = band.intersect(placed.rect);
band.is_positive()
.then(|| PagePart::new(Owner::Frame { block, side }, page, HitShape::Rect(band), PageLayer::Handle).cursor(CursorIcon::Move))
}));
}
let s = &session.objects;
+5 -3
View File
@@ -70,11 +70,13 @@ pub(crate) fn page_parts(
/// goes to [`PrepareTool`].
pub(crate) fn field_press(session: &mut PageSession, form: &[FormField], press: &PagePress) {
let Owner::PrepareField { field, widget } = press.owner else { return };
let PressPhase::Down { start, .. } = press.phase else { return };
let Some(start) = press.phase.start() else { return };
let Some(f) = form.get(field) else { return };
match start.button {
PointerButton::Secondary => super::context(form, field, widget, session),
PointerButton::Primary => {
PointerButton::Secondary if matches!(press.phase, PressPhase::Down { .. } | PressPhase::Release { click: true, .. }) => {
super::context(form, field, widget, session)
}
PointerButton::Primary if matches!(press.phase, PressPhase::Down { .. }) => {
let extend = press.mods.shift || press.mods.cmd;
session.prepare.select((f.name.clone(), widget), extend);
// The `Down` of a second primary press: the one double press, as `PressState::double_pressed` reads it.
+12 -4
View File
@@ -1146,6 +1146,8 @@ fn a_right_click_with_edit_text_on_a_paragraph_under_a_comment_selects_the_comme
assert_eq!(h.state().views[0].session.comments.primary(), Some((0, 0)), "the comment over the paragraph is selected");
assert!(h.query_by_label("Properties…").is_some(), "its menu opens");
assert_eq!(h.state().views[0].session.comments.context_at.map(|(page, _)| page), Some(0), "the menu is anchored on the page");
h.key_press(egui::Key::Escape);
h.run_steps(3);
// The rectangle ends at x 200; the line goes on.
let beside = at(&h, 230.0, 303.0);
right_click(&mut h, beside);
@@ -1732,17 +1734,23 @@ fn paste_from_a_right_click_where_two_pages_touch_keeps_to_the_first_page() {
let image = egui::ColorImage::from_rgba_unmultiplied([60, 40], &[50u8, 150, 250, 255].repeat(60 * 40));
egui::Event::PasteImage(Arc::new(image))
};
h.event(picture());
h.run_steps(1);
let mut png = Vec::new();
image::RgbImage::from_pixel(60, 40, image::Rgb([50, 150, 250])).write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png).unwrap();
let ctx_h = h.ctx.clone();
assert!(h.state_mut().paste_image_at(&ctx_h, 1, [100.0, 400.0]), "a picture across page 2's top edge");
assert!(
h.state_mut().apply_edit(
&ctx_h,
pdfcraft_engine::Edit::AddImage { page: 1, rect: Some([70.0, 380.0, 130.0, 420.0]), name: "picture.png".into(), bytes: Arc::new(png) },
),
"a picture across page 2's top edge"
);
h.state_mut().views[0].session.image_selection = None;
h.run_steps(4);
right_click(&mut h, seam);
assert_eq!(h.state().views[0].session.comments.context_at.map(|(page, _)| page), Some(0), "page 1 takes the right-click");
assert!(h.state().views[0].session.image_selection.is_none(), "page 2's picture is not selected for its menu");
h.event(picture());
h.get_by_label_contains("Paste").click();
h.get_by_label("Paste").click();
h.run_steps(3);
let images = |page| {
let s = h.state();