From 65105951e01499d361b8af3bc92a359133186168 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Thu, 19 Nov 2026 14:38:52 -0500 Subject: [PATCH] red8 g2: app red round 8 fixes --- apps/pdfcraft-cli/src/ui.rs | 8 +- crates/engine/src/catalog.rs | 36 ++++----- crates/engine/src/session/save.rs | 10 ++- crates/engine/src/signature_image.rs | 1 - .../ui-egui/examples/properties_scenarios.rs | 4 +- crates/ui-egui/src/canvas.rs | 32 +++++++- crates/ui-egui/src/canvas/signature_drag.rs | 80 ++++++++++++++++++- crates/ui-egui/src/dialogs/standards_ui.rs | 8 +- crates/ui-egui/src/tools/comments/menu.rs | 5 +- crates/ui-egui/src/tools/comments/state.rs | 14 ++-- crates/ui-egui/tests/it/comments.rs | 54 ++++++++----- crates/ui-egui/tests/it/pdf_links.rs | 4 +- crates/ui-egui/tests/it/preferences.rs | 33 +++++--- crates/ui-egui/tests/it/stamps.rs | 2 +- 14 files changed, 217 insertions(+), 74 deletions(-) diff --git a/apps/pdfcraft-cli/src/ui.rs b/apps/pdfcraft-cli/src/ui.rs index 032b51642f..832140b16e 100644 --- a/apps/pdfcraft-cli/src/ui.rs +++ b/apps/pdfcraft-cli/src/ui.rs @@ -14,8 +14,7 @@ use super::{CliError, stdout_line}; /// One request to a running app's control channel (`pdfcraft --control PORT`). pub(crate) fn ui(args: &[String]) -> Result<(), CliError> { validate_options("ui", args, UI_OPTIONS)?; - let port = flag(args, "--control") - .ok_or("ui: missing --control PORT (start the app with `pdfcraft --control PORT`)")?; + let port = flag(args, "--control").ok_or("ui: missing --control PORT (start the app with `pdfcraft --control PORT`)")?; let port = control_port(port).map_err(|e| format!("ui: --control {port}: {e}"))?; let env = EnvNames::for_app("PDFCRAFT"); let env_token = std::env::var(&env.token).ok().filter(|v| !v.trim().is_empty()); @@ -28,9 +27,8 @@ pub(crate) fn ui(args: &[String]) -> Result<(), CliError> { let token = client_token(supplied.as_deref(), token_file_given.as_deref(), &FlagNames::default(), &env).map_err(|e| format!("ui: {e}"))?; let pos = positional(args, UI_OPTIONS); - let method = *pos - .first() - .ok_or("ui: missing method (state, inspect, click, move, release, type, key, command, commands, set, open, screenshot, …)")?; + let method = + *pos.first().ok_or("ui: missing method (state, inspect, click, move, release, type, key, command, commands, set, open, screenshot, …)")?; let method = if method.starts_with("ui.") { method.to_string() } else { format!("ui.{method}") }; let mut params = serde_json::Map::new(); for kv in pos.iter().skip(1) { diff --git a/crates/engine/src/catalog.rs b/crates/engine/src/catalog.rs index 8affb889f1..ced85412f3 100644 --- a/crates/engine/src/catalog.rs +++ b/crates/engine/src/catalog.rs @@ -84,7 +84,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ title: "Export to", items: &[ item("Microsoft Word (.docx)", "file-text", "export.docx", Ready), - item("Spreadsheet (.xlsx)", "grid","export.xlsx", Planned("M10")), + item("Spreadsheet (.xlsx)", "grid", "export.xlsx", Planned("M10")), item("Presentation (.pptx)", "presentation", "export.pptx", Ready), item("Image (PNG)", "image", "export.image", Ready), item("Export all images", "image", "export.all_images", Ready), @@ -107,8 +107,8 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ items: &[ item("Add text", "type", "sign.fill.text", Ready), item("Checkmark", "check", "sign.fill.check", Ready), - item("Cross", "close","sign.fill.cross", Ready), - item("Dot", "target","sign.fill.dot", Ready), + item("Cross", "close", "sign.fill.cross", Ready), + item("Dot", "target", "sign.fill.dot", Ready), item("Line", "minus", "sign.fill.line", Ready), item("Date", "clock-3", "sign.fill.date", Ready), item("Signature", "signature", "sign.fill.signature", Ready), @@ -130,11 +130,11 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ title: "Modify page", items: &[ item("Edit text & images", "text-cursor-input", "edit.edit_text", Ready), - item("Rotate pages", "rotate_cw","page.rotate", Ready), + item("Rotate pages", "rotate_cw", "page.rotate", Ready), item("Insert pages", "file-plus-2", "page.insert", Ready), item("Delete pages", "trash-2", "page.delete", Ready), item("Extract pages", "file-output", "page.extract", Ready), - item("Organize pages", "layout_grid","page.organize", Ready), + item("Organize pages", "layout_grid", "page.organize", Ready), ], }, ToolSection { @@ -144,7 +144,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ item("Image", "image-plus", "edit.image", Ready), menu_item("Header and footer", "heading", &["edit.header_footer", "edit.header_footer.update", "edit.header_footer.remove"]), menu_item("Watermark", "stamp", &["edit.watermark", "edit.watermark.update", "edit.watermark.remove"]), - item("Link", "link","edit.link", Ready), + item("Link", "link", "edit.link", Ready), item("Bates numbering", "hash", "edit.bates", Ready), menu_item("Background", "palette", &["edit.background", "edit.background.update", "edit.background.remove"]), item("Attach file", "paperclip", "edit.attach", Ready), @@ -191,8 +191,8 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ ToolSection { title: "Page options", items: &[ - item("Page grid", "layout_grid","page.organize", Ready), - item("Rotate", "rotate_cw","page.rotate", Ready), + item("Page grid", "layout_grid", "page.organize", Ready), + item("Rotate", "rotate_cw", "page.rotate", Ready), item("Delete", "trash-2", "page.delete", Ready), item("Extract", "file-output", "page.extract", Ready), item("Insert", "file-plus-2", "page.insert", Ready), @@ -206,7 +206,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ item("Set page boxes", "square-dashed-mouse-pointer", "page.boxes", Ready), item("Crop pages", "crop", "page.crop", Ready), item("Duplicate pages", "copy-plus", "page.duplicate", Ready), - item("Reverse pages", "swap_vertical","page.reverse", Ready), + item("Reverse pages", "swap_vertical", "page.reverse", Ready), item("Page labels", "tag", "page.number", Ready), item("Page transitions", "presentation", "page.transitions", Planned("M4")), ], @@ -226,8 +226,8 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ items: &[ item("Sticky note", "sticky-note", "comment.note", Ready), item("Highlight text", "highlighter", "comment.highlight", Ready), - item("Underline", "text_underline","comment.underline", Ready), - item("Strikethrough", "text_strikethrough","comment.strikeout", Ready), + item("Underline", "text_underline", "comment.underline", Ready), + item("Strikethrough", "text_strikethrough", "comment.strikeout", Ready), item("Squiggly underline", "spline", "comment.squiggly", Ready), item("Text box", "type", "comment.freetext", Ready), ], @@ -283,7 +283,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ title: "Protect", items: &[ item("Protect with password", "lock", "protect.password", Ready), - item("Remove hidden information", "eye_off","protect.remove_hidden", Ready), + item("Remove hidden information", "eye_off", "protect.remove_hidden", Ready), ], }, ToolSection { @@ -291,7 +291,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ items: &[ item("Encrypt with certificate", "file-lock-2", "protect.certificate", Planned("M8")), item("Security properties", "shield-check", "protect.properties", Ready), - item("Remove security", "lock_open","protect.remove", Ready), + item("Remove security", "lock_open", "protect.remove", Ready), ], }, ], @@ -306,7 +306,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ sections: &[ToolSection { title: "Redact", items: &[ - item("Redact text and images", "rectangle","redact.mark", Ready), + item("Redact text and images", "rectangle", "redact.mark", Ready), item("Redact pages", "file-x", "redact.pages", Ready), item("Find text and redact", "file-search", "redact.search", Ready), item("Set properties", "settings-2", "redact.properties", Ready), @@ -347,7 +347,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ item("Field properties", "settings-2", "form.field.properties", Ready), item("Tab order by rows", "rows-3", "form.tab_order.row", Ready), item("Tab order by columns", "columns-3", "form.tab_order.column", Ready), - item("Calculation order", "list_numbered","form.calculation_order", Ready), + item("Calculation order", "list_numbered", "form.calculation_order", Ready), item("Flatten form fields", "layers", "form.flatten", Ready), item("Import data", "file-input", "form.import_data", Ready), item("Export data", "file-output", "form.export_data", Ready), @@ -357,10 +357,10 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ title: "Add form components", items: &[ item("Text field", "text-cursor-input", "form.add.text", Ready), - item("Text field table", "grid","form.add.text_table", Ready), + item("Text field table", "grid", "form.add.text_table", Ready), item("Checkbox", "check-circle-2", "form.add.checkbox", Ready), item("Radio button", "circle", "form.add.radio", Ready), - item("Drop-down list", "chevron_down","form.add.combo", Ready), + item("Drop-down list", "chevron_down", "form.add.combo", Ready), item("List box", "list", "form.add.list", Ready), item("Button", "square", "form.add.button", Ready), item("Image field", "image", "form.add.image", Ready), @@ -482,7 +482,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ item("Open accessibility report", "file-text", "a11y.report", Ready), item("Add alternate text", "image", "a11y.alt_text", Ready), item("Tags panel", "tag", "a11y.tags", Ready), - item("Fix reading order", "list_numbered","a11y.reading_order", Planned("M12")), + item("Fix reading order", "list_numbered", "a11y.reading_order", Planned("M12")), ], }], }, diff --git a/crates/engine/src/session/save.rs b/crates/engine/src/session/save.rs index 2e26be4056..52085888ab 100644 --- a/crates/engine/src/session/save.rs +++ b/crates/engine/src/session/save.rs @@ -212,10 +212,12 @@ impl Session { // The working bytes hold typed Password-field values (#3926, #3944): a recovery file // is written from a copy without them, and none is written if that copy fails. let bytes = match d.editor.as_ref().filter(|e| pdfcraft_forms::has_password_values(&e.cos) || pdfcraft_xfa::has_password_values(&e.cos)) { - Some(e) => match writable(&e.cos).and_then(|c| write_incremental(&c, &SaveOptions::default()).map_err(|e| EditError::Write(e.to_string()))) { - Ok(b) => Arc::new(b), - Err(_) => return None, - }, + Some(e) => { + match writable(&e.cos).and_then(|c| write_incremental(&c, &SaveOptions::default()).map_err(|e| EditError::Write(e.to_string()))) { + Ok(b) => Arc::new(b), + Err(_) => return None, + } + } None => d.bytes.clone(), }; Some(RecoverySnapshot { diff --git a/crates/engine/src/signature_image.rs b/crates/engine/src/signature_image.rs index dde9c0cd62..f9a22f4084 100644 --- a/crates/engine/src/signature_image.rs +++ b/crates/engine/src/signature_image.rs @@ -220,7 +220,6 @@ impl SignatureImage { pdfcraft_sign::Graphic::Image { width: side(self.size[0]), height: side(self.size[1]), rgba: self.rgba.clone() } } - /// The user-space box for the image with its left edge at `at` (a user-space point on `page`), /// vertically centered, with the same 150 pt width cap as typed names. Left and centered are /// as displayed: on a page with `/Rotate` the box runs along the turned page's axes. diff --git a/crates/ui-egui/examples/properties_scenarios.rs b/crates/ui-egui/examples/properties_scenarios.rs index ec21861d41..348709479c 100644 --- a/crates/ui-egui/examples/properties_scenarios.rs +++ b/crates/ui-egui/examples/properties_scenarios.rs @@ -8,12 +8,12 @@ use std::io::{BufRead, Read, Write}; use std::path::PathBuf; use std::sync::Arc; +use craft::ui::dialog::dialog_id; +use craft::ui::patterns::form_dialogs::HostedParamDialog; use egui::accesskit::Role; use egui_kittest::Harness; use egui_kittest::kittest::{NodeT, Queryable}; use pdfcraft_engine::{DocId, Edit, Session}; -use craft::ui::dialog::dialog_id; -use craft::ui::patterns::form_dialogs::HostedParamDialog; use pdfcraft_ui_egui::{PdfCraftApp, PropsTab}; use serde::Deserialize; use serde_json::{Value, json}; diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index a40c2043c9..4f5b55ce55 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -17,6 +17,7 @@ use craft::ui::contract::Show as _; use craft::ui::display::Text; use craft::ui::list::OpenSet; use craft::ui::primitives::TextureStatistics; +use craft::ui::primitives::textures::TextureState; use craft::ui::runtime::env::Env; use craft::ui::runtime::focus::{self, FocusTarget}; use craft::ui::style::DataColor; @@ -839,6 +840,8 @@ struct PageBodyCx<'a> { rotation: u16, /// The view's current page this pass. current: usize, + /// The scale the pages render at this pass, which the dragged comment's layers render at too. + render_scale: f32, /// Full screen: the page, display and rotation it shows, captured before the page view holds the view state; /// `None` outside full screen. present_at: Option, @@ -1297,6 +1300,31 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession, let hover = comments::Hover { pointer, redact: cx.redact_hover, pick, allowed: cx.allowed }; comments::show(ui, body, session, cx.rotation, cx.info, cx.prefs, cx.tool, hover); } + // The comment being dragged, drawn from its own layers where it goes, over the page that still shows it where it + // was. A page whose picture is of this revision has the released move: its layer settles. + { + let ctx = ui.ctx().clone(); + let movable = matches!(cx.tool, QuickTool::Select | QuickTool::Fill(_)) && !cx.comments_hidden; + let target = movable.then(|| session.comments.primary()).flatten(); + let loading = |page: usize| body.pages.iter().any(|p| p.page == page && matches!(p.picture, TextureState::Loading { .. })); + let drag = &mut session.signature_drag; + drag.prepare(&ctx, cx.doc, target, cx.render_scale); + for placed in body.pages.iter().filter(|p| !loading(p.page)) { + drag.page_received(placed.page); + session.comments.page_rendered(placed.page); + } + let stale = drag.moving_page().is_some_and(loading); + drag.prepare_move(&ctx, cx.doc, &session.comments, session.pending_edit.as_ref(), stale, cx.render_scale); + let map = comments::PageMap::new(cx.info, body.pages, cx.rotation, body.view); + for placed in body.pages { + let size = cx.sizes.get(placed.page).copied().unwrap_or_default(); + let xf = PageXform::of(placed, cx.rotation, size); + let pcx = + comments::PageCx { page: placed.page, xf: &xf, info: cx.info, prefs: cx.prefs, allowed: cx.allowed, hidden: cx.comments_hidden }; + signature_drag::DragLayer::new(&session.signature_drag, &pcx, &map, cx.tool, &session.comments, session.pending_edit.as_ref()) + .show_at(ui, body.rect); + } + } if cx.calc_order { let hovered = match &parts_out.hovered { Some((Owner::Field { field, .. } | Owner::PrepareField { field, .. }, _)) => { @@ -1499,7 +1527,8 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu let find_marks: Vec = view.find.as_ref().map(Find::marks).unwrap_or_default(); let present_at = presenting.then_some(presenter::PresentAt { current: view.view.current, display: view.view.display, rotation: view.view.rotation }); - let border = if view.view.page_gaps { PageBorder::DropShadow } else { PageBorder::None }; + // Shadows only with the preference on, and only between gaps: they would darken the page before when pages touch. + let border = if view.view.page_gaps && app.show_page_edge_shadows { PageBorder::DropShadow } else { PageBorder::None }; let keep = view.session.presenter.keep_pages(); if view.momentary_options != navigation { view.momentary = Momentary::new(navigation); @@ -1568,6 +1597,7 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu chosen, rotation: state.rotation, current: state.current, + render_scale: scale, sizes: &page_sizes[..], view_key, tools, diff --git a/crates/ui-egui/src/canvas/signature_drag.rs b/crates/ui-egui/src/canvas/signature_drag.rs index 6c3b3120b5..d8689e3dbe 100644 --- a/crates/ui-egui/src/canvas/signature_drag.rs +++ b/crates/ui-egui/src/canvas/signature_drag.rs @@ -2,10 +2,13 @@ //! follows each pointer frame, moved or resized, without editing the PDF. Any other comment //! follows the pointer while it is moved: its own layer is drawn where it goes. +use craft::behavior::{Input, Sense}; use craft::review::AnnotationEdit; +use craft::ui::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Role}; use craft::ui::primitives::textures::{CachedTexture, TextureStore, TextureStoreOptions}; use craft::ui::primitives::{Draw, backdrop}; -use egui::{ColorImage, Pos2, Rect, TextureId, pos2, vec2}; +use craft::ui::style::{ComponentStyle, Metrics, StyleCx}; +use egui::{ColorImage, Pos2, Rect, Response, TextureId, Vec2, pos2, vec2}; use pdfcraft_engine::{Document, Edit}; use pdfcraft_render::{PageInfo, RenderPool, RenderRequest, Tile}; @@ -383,6 +386,81 @@ impl SignatureDrag { } } +/// The style of the drag's layers: they paint the document's own pixels and nothing of the theme. +#[derive(Clone, Debug, PartialEq, ComponentStyle)] +#[non_exhaustive] +pub struct DragLayerStyle { + #[style(metrics)] + metrics: Metrics, +} + +/// The comment being dragged over one page, drawn from the drag's layers where it goes: the selected stamp's +/// ([`SignatureDrag::paint`]), then any other comment being moved ([`SignatureDrag::paint_move`]). Paint only. +// `unregistered`: it needs a live document and a drag under way, so the suite has no sample of it. +#[derive(craft::ui::contract::Component)] +#[component(canvas_control, unregistered)] +pub(crate) struct DragLayer<'a> { + #[common] + common: Common, + drag: &'a SignatureDrag, + cx: &'a PageCx<'a>, + map: &'a PageMap<'a>, + tool: QuickTool, + cv: &'a CommentView, + pending: Option<&'a Edit>, +} + +impl<'a> DragLayer<'a> { + pub(crate) fn new( + drag: &'a SignatureDrag, + cx: &'a PageCx<'a>, + map: &'a PageMap<'a>, + tool: QuickTool, + cv: &'a CommentView, + pending: Option<&'a Edit>, + ) -> Self { + DragLayer { common: Common::new(), drag, cx, map, tool, cv, pending } + } +} + +impl Component for DragLayer<'_> { + const ROLE: Role = Role::GROUP; + const ALT_ROLES: &'static [Role] = &[Role::None]; + const INPUT: Input = Input::Display; + const PARTS: bool = false; + const STOPS: bool = false; + const OVERLAYS: bool = false; + const SHOWS_LABEL: bool = false; + type Style = DragLayerStyle; + type Output = Response; + + fn style(_: &StyleCx<'_>, _: DragLayerStyleKey) -> DragLayerStyle { + DragLayerStyle { metrics: Metrics::new() } + } + + fn measure(&mut self, _: &MeasureCx<'_, Self>) -> Vec2 { + Vec2::ZERO + } + + fn sense(&self) -> Sense { + Sense::empty() + } + + fn paint(&mut self, ui: &mut PaintUi<'_>, _: &Cx<'_, Self>) { + let draw = ui.draw(); + self.drag.paint(&draw, self.cx, self.map, self.tool, self.cv, self.pending); + self.drag.paint_move(&draw, self.cx, self.map, self.cv, self.pending); + } + + fn access(&self, access: &mut Access, _: &Cx<'_, Self>) { + access.role(Role::None); + } + + fn finish(self, cx: Cx<'_, Self>) -> Response { + cx.response.clone() + } +} + impl Front { /// The key a stamp front's pixels were put in the store under. fn stored(&self) -> Option { diff --git a/crates/ui-egui/src/dialogs/standards_ui.rs b/crates/ui-egui/src/dialogs/standards_ui.rs index 6db1a81fff..fed2c22a22 100644 --- a/crates/ui-egui/src/dialogs/standards_ui.rs +++ b/crates/ui-egui/src/dialogs/standards_ui.rs @@ -186,8 +186,12 @@ impl StackDialog for PdfaDialog { Some(v) => { let findings: Vec = v.iter().enumerate().map(|(n, i)| finding(n as u64, i)).collect(); FindingsSummary::new(&findings).show(ui); - FindingsList::new(tl!("PDF/A problems").to_string()) - .show_items(ui, &Findings::new(&findings), &mut |key, icx| findings[*key as usize].row(&icx.words::())); + // The dialog's body scrolls: the list takes its full height and owns no scroll of its own. + FindingsList::new(tl!("PDF/A problems").to_string()).natural_height(true).show_items( + ui, + &Findings::new(&findings), + &mut |key, icx| findings[*key as usize].row(&icx.words::()), + ); } } true diff --git a/crates/ui-egui/src/tools/comments/menu.rs b/crates/ui-egui/src/tools/comments/menu.rs index 2fad31b882..d422830c79 100644 --- a/crates/ui-egui/src/tools/comments/menu.rs +++ b/crates/ui-egui/src/tools/comments/menu.rs @@ -2,7 +2,7 @@ use craft::behavior::{IconId, Mixed}; use craft::keymap::CommandRef; use craft::ui::buttons::{IconButton, ToggleButton}; use craft::ui::choice::Swatch; -use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _}; +use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _, clicked}; use craft::ui::display::Divider; use craft::ui::form::SliderField; @@ -229,7 +229,8 @@ fn popover_from(ui: &mut egui::Ui, label: &str, opener: impl FnOnce(&mut egui::U let resp = opener(ui); let key = resp.id.with("popover-open"); let mut open = ui.memory(|m| m.data.get_temp::(key)).unwrap_or(false); - if resp.clicked() { + // The framework's click rule: a click, or the opener activated by key or by AccessKit. + if clicked(&resp) { open = !open; } let mut body = Some(body); diff --git a/crates/ui-egui/src/tools/comments/state.rs b/crates/ui-egui/src/tools/comments/state.rs index 5d619f440d..e09c587c61 100644 --- a/crates/ui-egui/src/tools/comments/state.rs +++ b/crates/ui-egui/src/tools/comments/state.rs @@ -249,9 +249,10 @@ impl CommentView { self.slots = next; } - /// Every selected comment, the one the handles belong to first. + /// Every selected comment, the one the handles belong to first, then the others in the order they were selected. pub fn selection(&self) -> Vec<(usize, usize)> { - self.tool.selected.iter().rev().map(|id| bridge::key_of(*id)).collect() + let Some((lead, others)) = self.tool.selected.split_last() else { return Vec::new() }; + std::iter::once(lead).chain(others).map(|id| bridge::key_of(*id)).collect() } /// The selected comment the handles, the properties and the context menu act on: the last one selected. @@ -271,8 +272,8 @@ impl CommentView { } /// Select `keys`, the first being the lead (the one with the handles): repeated keys count once, at - /// their first place. The tool keeps its primary last, so the others are stored in reverse and the - /// lead last: [`Self::selection`] gives `keys` back in order. + /// their first place. The tool keeps its primary last, so the others are stored in order and the + /// lead after them: [`Self::selection`] gives `keys` back in order. pub fn select_keys(&mut self, keys: &[(usize, usize)]) { let mut unique: Vec<(usize, usize)> = Vec::with_capacity(keys.len()); for key in keys { @@ -280,7 +281,10 @@ impl CommentView { unique.push(*key); } } - self.tool.selected = unique.into_iter().rev().map(|(p, i)| bridge::id_of(p, i)).collect(); + if !unique.is_empty() { + unique.rotate_left(1); + } + self.tool.selected = unique.into_iter().map(|(p, i)| bridge::id_of(p, i)).collect(); self.member = None; } diff --git a/crates/ui-egui/tests/it/comments.rs b/crates/ui-egui/tests/it/comments.rs index 37280964cf..9759b53130 100644 --- a/crates/ui-egui/tests/it/comments.rs +++ b/crates/ui-egui/tests/it/comments.rs @@ -1299,7 +1299,7 @@ fn comment_properties_change_appearance_and_author() { drag_pt(&mut h, (40.0, 100.0), (140.0, 40.0)); open_comment_props(&mut h, 0, 0); h.run_steps(2); - h.get_by_label("Rectangle Properties"); + h.get_by_role_and_label(Role::Dialog, "Rectangle Properties"); { let s = h.state(); assert_eq!(s.session.get(s.views[0].id).unwrap().comment_props(0, 0).unwrap().width, Some(2.0)); @@ -1561,31 +1561,32 @@ fn the_panel_preserves_threads_source_order_and_unfiltered_page_counts() { app.views[0].session.comments.panel.filter.hidden_authors.push("Beta".into()); app.views[0].session.comments.select_only((0, 0)); }); - h.get_by_label("First root"); + // The panel names a card or reply row by its author, text and date. + h.get_by_label_contains("First root"); h.get_by_label("Page 1"); h.get_by_label("3"); // All three page roots count, including the two filtered out. - assert_eq!(h.query_all_by_label("Duplicate root").count(), 0); - assert_eq!(h.query_all_by_label("Unnamed root").count(), 0); + assert_eq!(h.query_all_by_label_contains("Duplicate root").count(), 0); + assert_eq!(h.query_all_by_label_contains("Unnamed root").count(), 0); assert!( - h.get_by_label("Needle first reply").rect().top() < h.get_by_label("Second reply").rect().top(), + h.get_by_label_contains("Needle first reply").rect().top() < h.get_by_label_contains("Second reply").rect().top(), "replies follow source order, not dates" ); h.get_by_label("Accepted"); h.get_by_label("Mark with checkmark"); // The later Unmarked reply wins independently. - assert_eq!(h.query_all_by_label("Status-only token").count(), 0, "status text is searchable but is not a displayed reply"); + assert_eq!(h.query_all_by_label_contains("Status-only token").count(), 0, "status text is searchable but is not a displayed reply"); h.state_mut().views[0].session.comments.panel.filter.hidden_authors.clear(); h.run_steps(2); // The replies point at the first root: sharing its /NM doesn't give the other its thread // (or a search match on that thread). - assert_eq!(h.query_all_by_label("Duplicate root").count(), 0); - assert_eq!(h.query_all_by_label("Needle first reply").count(), 1); + assert_eq!(h.query_all_by_label_contains("Duplicate root").count(), 0); + assert_eq!(h.query_all_by_label_contains("Needle first reply").count(), 1); h.state_mut().views[0].session.comments.panel.search = "status-only token".into(); h.state_mut().views[0].session.comments.panel.filter.hidden_statuses.push(ReviewStatus::Rejected); h.state_mut().views[0].session.comments.panel.filter.hidden_checks.push(true); h.run_steps(2); - h.get_by_label("First root"); - assert_eq!(h.query_all_by_label("Duplicate root").count(), 0); + h.get_by_label_contains("First root"); + assert_eq!(h.query_all_by_label_contains("Duplicate root").count(), 0); h.state_mut().views[0].session.comments.panel.filter.hidden_statuses.push(ReviewStatus::Accepted); h.run_steps(2); @@ -1598,8 +1599,8 @@ fn the_panel_preserves_threads_source_order_and_unfiltered_page_counts() { h.state_mut().views[0].session.comments.panel.search = "unnamed root".into(); h.state_mut().views[0].session.comments.panel.filter.hidden_checks.clear(); h.run_steps(2); - h.get_by_label("Unnamed root"); - assert_eq!(h.query_all_by_label("Needle first reply").count(), 0, "nothing replies to the unnamed root"); + h.get_by_label_contains("Unnamed root"); + assert_eq!(h.query_all_by_label_contains("Needle first reply").count(), 0, "nothing replies to the unnamed root"); } // Contributor-original PDF. A status is set on a reply (its /IRT names the reply, ISO 32000-2 @@ -1864,20 +1865,22 @@ fn replies_that_lead_nowhere_stay_comments_and_deeper_replies_join_their_thread( for orphan in ["Points at itself", "Points at an unlisted note", "Points at a pop-up", "Points at a link", "Points at a form field", "Loop one", "Loop two"] { - assert!(h.get_by_label(orphan).rect().top() > h.get_by_label("Page 2").rect().top(), "{orphan}"); + // The panel names a card or reply row by its author, text and date. + assert!(h.get_by_label_contains(orphan).rect().top() > h.get_by_label("Page 2").rect().top(), "{orphan}"); } // A reply to a reply joins the thread of the comment it starts from, also when that comment // has no /NM. - let (parent, direct, deeper) = (h.get_by_label("Unnamed parent"), h.get_by_label("Direct reply"), h.get_by_label("Reply to the reply")); + let (parent, direct, deeper) = + (h.get_by_label_contains("Unnamed parent"), h.get_by_label_contains("Direct reply"), h.get_by_label_contains("Reply to the reply")); assert!(parent.rect().top() < direct.rect().top() && direct.rect().top() < deeper.rect().top()); - assert!(deeper.rect().top() < h.get_by_label("Struck words").rect().top(), "under its own thread"); + assert!(deeper.rect().top() < h.get_by_label_contains("Struck words").rect().top(), "under its own thread"); // Comments: the unnamed parent, the strikeout and the seven on page 2. Replies: the two // replies, not the Replace Text caret grouped with its strikeout. h.get_by_label("9"); h.get_by_label("2 replies"); // A status whose comment no page lists is not a comment: no card, and nothing to pick on the // page where it sits. - assert_eq!(h.query_all_by_label("Stray status").count(), 0); + assert_eq!(h.query_all_by_label_contains("Stray status").count(), 0); click_pt(&mut h, (250.0, 30.0)); assert!(h.state().views[0].session.comments.selection().is_empty()); } @@ -2055,7 +2058,7 @@ fn comments_take_checkmarks_lock_hide_and_summarize() { h.get_by_label("Mark with checkmark").click(); h.run_steps(3); assert!(comments(&h).iter().any(|a| a.state.as_deref() == Some("Marked"))); - h.get_by_label("Remove checkmark"); + h.get_by_role_and_label(Role::Button, "Remove checkmark"); // "…" ▸ Copy text puts the comment's text on the clipboard. let ctx_h = h.ctx.clone(); @@ -2272,8 +2275,17 @@ fn the_panel_shows_each_reviewers_status_and_only_my_checkmark() { drag_pt(&mut h, (160.0, 100.0), (260.0, 40.0)); h.set_option("quick", "select").unwrap(); h.state_mut().views[0].session.comments.clear_selection(); + // The panel names a card by its author and text: each shape gets a text to tell its card by. + let oval = comments(&h).iter().find(|a| a.subtype == "Circle").map(|a| a.index).expect("the oval"); + for (index, text) in [(0, "The rectangle"), (oval, "The oval")] { + let ctx_h = h.ctx.clone(); + h.state_mut().apply_edit(&ctx_h, pdfcraft_engine::Edit::SetAnnotationContents { page: 0, index, text: text.into() }); + } h.run_steps(2); - let cards = |h: &Harness<'static, PdfCraftApp>| (h.query_all_by_label("Rectangle").count(), h.query_all_by_label("Oval").count()); + let cards = |h: &Harness<'static, PdfCraftApp>| { + (h.query_all_by_label_contains("The rectangle").count(), h.query_all_by_label_contains("The oval").count()) + }; + assert_eq!(cards(&h), (1, 1), "both cards show"); let shown = cards(&h); h.state_mut().views[0].session.comments.panel.filter.hidden_statuses = vec![ReviewStatus::Rejected]; h.run_steps(2); @@ -3969,9 +3981,9 @@ fn a_pop_up_threads_its_replies_and_takes_a_new_one() { assert!(h.query_all_by(|n| n.placeholder() == Some("Add a reply")).next().is_none(), "the box closes"); } -/// A pop-up window's box holding `text` (a comment's or a reply's). +/// A pop-up window's text `text` (a comment's or a reply's): the comment's box, or a reply's read-only text. fn shows_text(n: &egui_kittest::kittest::AccessKitNode<'_>, text: &str) -> bool { - n.role() == Role::MultilineTextInput && n.value().as_deref() == Some(text) + matches!(n.role(), Role::MultilineTextInput | Role::Label) && n.value().as_deref() == Some(text) } /// On a page turned a quarter (View ▸ Rotate View), a resized pop-up window stays where it is on @@ -4815,7 +4827,7 @@ fn edit_delete_from_a_native_menu_under_the_full_screen_prompt_leaves_the_commen let ctx_h = h.ctx.clone(); h.state_mut().open_bytes(&ctx_h, "deck.pdf", None, deck).expect("the deck opens"); h.run_steps(3); - let prompt = |h: &Harness<'static, PdfCraftApp>| h.query_by_label("Open in Full Screen mode?").is_some(); + let prompt = |h: &Harness<'static, PdfCraftApp>| h.query_by_role_and_label(Role::Dialog, "Open in Full Screen mode?").is_some(); assert!(prompt(&h), "the full-screen prompt is open"); support::fire_menu(&mut h, craft::menu::CommandRef::with_params("window.document", serde_json::json!({ "index": 0 }))); h.run_steps(3); diff --git a/crates/ui-egui/tests/it/pdf_links.rs b/crates/ui-egui/tests/it/pdf_links.rs index 361cc2ac20..8d918a3fde 100644 --- a/crates/ui-egui/tests/it/pdf_links.rs +++ b/crates/ui-egui/tests/it/pdf_links.rs @@ -113,8 +113,8 @@ fn link_properties_sets_the_page_view_zoom() { h.get_by_role_and_label(Role::Dialog, "Create Link"); h.get_by_label("Go to a page view").click(); h.run_steps(3); - // The field around the zoom choice carries its name too: the choice is the one that isn't the group. - h.get_by(|n| n.label().as_deref() == Some("Zoom") && n.role() != Role::Group).click(); + // The field's caption and the toolbar's zoom carry the name too: the choice is the drop-down. + h.get_by_role_and_label(Role::ComboBox, "Zoom").click(); h.run_steps(3); h.get_by_role_and_label(Role::Button, "200%").scroll_to_me(); h.run_steps(3); diff --git a/crates/ui-egui/tests/it/preferences.rs b/crates/ui-egui/tests/it/preferences.rs index 71369262b8..6642e1bb15 100644 --- a/crates/ui-egui/tests/it/preferences.rs +++ b/crates/ui-egui/tests/it/preferences.rs @@ -41,7 +41,7 @@ fn harness() -> H { /// Whether the Preferences window is on screen: its page list names the first page while it is open. fn preferences_shown(h: &H) -> bool { - h.query_by_label("General & Interface").is_some() + h.query_by_role_and_label(egui::accesskit::Role::ListItem, "General & Interface").is_some() } fn click(h: &mut H, label: &str) { @@ -75,6 +75,8 @@ fn cases() -> Vec { name: "layout and continuous on the active view", page: "Documents and view", edit: |h| { + // A choice row is a drop-down: its options show once it opens. + click(h, "Default page display"); click(h, "Two-page view"); click(h, "Continuous scrolling"); }, @@ -83,16 +85,24 @@ fn cases() -> Vec { v.display == craft::pages::PageDisplay::TwoUp && v.continuous != crate::control::new_app().views.first().map_or(true, |_| true) }, }, - Case { name: "units", page: "Documents and view", edit: |h| click(h, Unit::Millimetres.label()), applied: |a| a.units == Unit::Millimetres }, + Case { + name: "units", + page: "Documents and view", + edit: |h| { + click(h, "Units"); + click(h, Unit::Millimetres.label()); + }, + applied: |a| a.units == Unit::Millimetres, + }, Case { name: "tools side and rail side", page: "General & Interface", edit: |h| { - // The tools row comes first, then the rail row; each has a Left and a Right option. - h.get_all_by_label("Right").next().unwrap().click(); - h.run_steps(3); - h.get_all_by_label("Left").nth(1).unwrap().click(); - h.run_steps(3); + // Each side row is a drop-down of Left and Right. + click(h, "Tools panel side"); + click(h, "Right"); + click(h, "Navigation rail side"); + click(h, "Left"); }, applied: |a| { let dock = side_panels::state(a); @@ -102,7 +112,10 @@ fn cases() -> Vec { Case { name: "animation effects", page: "General & Interface", - edit: |h| click(h, "Off"), + edit: |h| { + click(h, "Animation effects"); + click(h, "Off"); + }, applied: |a| a.animation_effects == MotionChoice::Off, }, Case { @@ -131,7 +144,9 @@ fn edited(case: &Case) -> H { let mut h = harness(); h.state_mut().open_preferences(); h.run_steps(4); - click(&mut h, case.page); + // The page list's row, not the heading of the page it shows. + h.get_by_role_and_label(egui::accesskit::Role::ListItem, case.page).click(); + h.run_steps(3); (case.edit)(&mut h); h } diff --git a/crates/ui-egui/tests/it/stamps.rs b/crates/ui-egui/tests/it/stamps.rs index e8da7aee2c..7a810354fe 100644 --- a/crates/ui-egui/tests/it/stamps.rs +++ b/crates/ui-egui/tests/it/stamps.rs @@ -109,7 +109,7 @@ fn creating_placing_and_keeping_custom_stamps() { let ctx = h.ctx.clone(); h.state_mut().start_custom_stamp(&ctx, "logo.png".into(), png); h.run_steps(2); - h.get_by_label("Create Custom Stamp"); + h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Create Custom Stamp"); h.get_by_label("Category").click(); h.run_steps(1); h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);