From a793a204851031de5796040d55461c8062a3beb0 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Thu, 19 Nov 2026 14:39:14 -0500 Subject: [PATCH] red8 g6: 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/navigation.rs | 24 +++++++++++-- crates/ui-egui/src/canvas/page_overlays.rs | 21 +++++++---- crates/ui-egui/src/canvas/page_tools.rs | 4 +-- crates/ui-egui/src/commands.rs | 30 ++++++++-------- crates/ui-egui/src/commands/catalog.rs | 14 +++++--- crates/ui-egui/src/dialogs/shortcuts.rs | 13 ++----- crates/ui-egui/src/workflows/js_dialogs.rs | 13 +++---- crates/ui-egui/tests/it/view.rs | 23 ++++++++---- crates/ui-egui/tests/it/viewer.rs | 7 ++-- 14 files changed, 125 insertions(+), 83 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/navigation.rs b/crates/ui-egui/src/canvas/navigation.rs index bcc678d1c8..f37760a7e9 100644 --- a/crates/ui-egui/src/canvas/navigation.rs +++ b/crates/ui-egui/src/canvas/navigation.rs @@ -135,9 +135,18 @@ impl DocView { /// top-left at its zoom (null or 0 keeps the zoom); `/Fit`, `/FitH` and `/FitV` switch to fit /// page, width and height with `top` or `left` at the window's edge; `/FitR` zooms so the /// rectangle fits, centred. The `B` (content box) forms are read as the page. A null `/XYZ` - /// coordinate keeps the reader's place: that axis of the view is not moved, as Acrobat does. - /// A point past the end of the document scrolls as far as it can. + /// coordinate keeps the reader's place in user space, as Acrobat does: the coordinate at the + /// window's top-left now is the one put there on the new page. A point past the end of the + /// document scrolls as far as it can. pub fn go_to_dest(&mut self, page: usize, dest: DestView, info: &DocInfo) { + let kept = match dest { + DestView::Xyz { left, top, .. } if left.is_none() || top.is_none() => self.place_at_corner(info), + _ => None, + }; + let dest = match (dest, kept) { + (DestView::Xyz { left, top, zoom }, Some([x, y])) => DestView::Xyz { left: left.or(Some(x)), top: top.or(Some(y)), zoom }, + (dest, _) => dest, + }; self.go_to_page(page); let page = self.view.current; let Some(p) = info.pages.get(page) else { return }; @@ -188,6 +197,17 @@ impl DocView { } } + /// The user-space point of the current page at the window's top-left as far as pages go (past + /// the side gutter) in the last pass, if that page was drawn. + fn place_at_corner(&self, info: &DocInfo) -> Option<[f32; 2]> { + let page = self.view.current; + let xf = self.page_xform(page)?; + let side = self.spacing.as_ref().map_or(0.0, |spacing| spacing.side as f32); + let (vx, vy) = xf.screen_to_view(self.viewport_rect().min + egui::vec2(side, 0.0)); + let u = info.pages.get(page)?.view_to_user(vx, vy); + Some([u[0], u[1]]) + } + /// Next page (`true`) or previous page. In two-page view this moves a whole spread: the other /// page of the spread is already on screen, so stepping to it wouldn't move the view (#70). pub fn step_page(&mut self, forward: bool) { diff --git a/crates/ui-egui/src/canvas/page_overlays.rs b/crates/ui-egui/src/canvas/page_overlays.rs index d894e7c571..e9bae9bc96 100644 --- a/crates/ui-egui/src/canvas/page_overlays.rs +++ b/crates/ui-egui/src/canvas/page_overlays.rs @@ -432,8 +432,10 @@ pub struct PageOverlaysStyle { tab_ink: StyleColor, /// The colour of every verdict tone. tones: Vec<(Tone, StyleColor)>, - /// The badge outline's width, and how far it stands off the widget. + /// The badge outline's width, and how far it stands off the widget; also a required field's outline width. outline: f32, + /// The outline width of a field that isn't required. + field_line: f32, /// The corners of the badge outline and the flash. corners: CornerRadius, /// How far the flash and the compare marks stand off what they mark. @@ -509,6 +511,7 @@ impl Component for PageOverlays<'_> { tab_ink: cx.color(colors.text.on_accent), tones, outline: tokens.stroke.thick, + field_line: tokens.stroke.thin, corners: CornerRadius::same(tokens.shape.radius.sm.round().clamp(0.0, 255.0) as u8), grow: tokens.space.gap.inline, } @@ -553,20 +556,26 @@ impl PageOverlays<'_> { fn paint_field_highlights(&self, draw: &Draw<'_>, style: &PageOverlaysStyle) { for field in self.doc.form.iter().filter(|f| f.kind != FormFieldKind::PushButton) { let required = field.has(pdfcraft_engine::field_flags::REQUIRED); - let (width, edge) = if required { (StrokeWidth::Medium, style.required_edge) } else { (StrokeWidth::Thin, style.field_edge) }; + let (width, line, edge) = if required { + (StrokeWidth::Thick, style.outline, style.required_edge) + } else { + (StrokeWidth::Thin, style.field_line, style.field_edge) + }; for widget in field.widgets.iter().filter(|w| w.page == Some(self.page) && !w.hidden && !w.read_only) { let rect = self.xf.user_rect_f64(&self.doc.info, self.page, widget.rect); // The page transform can turn a finite widget into one the screen cannot place. if !rect.is_finite() { continue; } - let shape = if widget.round { - PaintShape::Circle(rect.center(), rect.width().min(rect.height()) / 2.0) + // The outline lies inside the widget: a rectangle strokes inside its edge, a circle on its radius. + let radius = rect.width().min(rect.height()) / 2.0; + let (shape, outline) = if widget.round { + (PaintShape::Circle(rect.center(), radius), PaintShape::Circle(rect.center(), radius - line / 2.0)) } else { - PaintShape::Rect(rect, CornerRadius::ZERO) + (PaintShape::Rect(rect, CornerRadius::ZERO), PaintShape::Rect(rect, CornerRadius::ZERO)) }; draw.fill(&shape, style.field_fill); - draw.stroke(&shape, width, edge); + draw.stroke(&outline, width, edge); } } } diff --git a/crates/ui-egui/src/canvas/page_tools.rs b/crates/ui-egui/src/canvas/page_tools.rs index b367f70d7a..cc0622da77 100644 --- a/crates/ui-egui/src/canvas/page_tools.rs +++ b/crates/ui-egui/src/canvas/page_tools.rs @@ -516,8 +516,8 @@ pub(crate) fn edit_text_press( geo: PageGeometry<'_>, tool: QuickTool, ) -> Option { - let Mods { cmd, shift, .. } = press.mods; - if (shift || cmd) && crate::tools::object_ui::modified_press(session, doc, info, press, geo) { + let Mods { cmd, ctrl, shift, .. } = press.mods; + if (shift || cmd || ctrl) && crate::tools::object_ui::modified_press(session, doc, info, press, geo) { return None; } match press.owner { diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs index 0140fb04b4..5589b9a861 100644 --- a/crates/ui-egui/src/commands.rs +++ b/crates/ui-egui/src/commands.rs @@ -65,7 +65,16 @@ impl PdfCraftApp { if self.run_catalog_command(ctx, fired) { return; } - self.execute(ctx, id); + // In Organize the clipboard rows and keys are the picked pages' (the catalog enables them as + // `page.copy`, `page.cut` and `page.paste`); the registry's text Copy itself stays off there. + let organize = self.active.and_then(|i| self.views.get(i)).is_some_and(|v| v.organize); + let page_command = match id { + "edit.copy" => Some("page.copy"), + crate::menus::CUT => Some("page.cut"), + crate::menus::PASTE => Some("page.paste"), + _ => None, + }; + self.execute(ctx, page_command.filter(|_| organize).unwrap_or(id)); } /// Answers a key press whose command only the app's own state disabled: the user is told @@ -198,7 +207,12 @@ impl PdfCraftApp { || spec.needs == commands::Needs::Redo && self.open_box_can_redo()) && (spec.id != "edit.copy" || self.active.and_then(|i| self.views.get(i)).is_some_and(|v| { - !v.organize && (v.session.all_text || v.selection_waits_for_text().is_some() || v.selected_text().is_some_and(|t| !t.is_empty())) + // Selected text, or a picked picture, which Copy takes in its original format. + !v.organize + && (v.session.all_text + || v.selection_waits_for_text().is_some() + || v.selected_text().is_some_and(|t| !t.is_empty()) + || v.session.picked_image.is_some()) })) && (spec.needs != commands::Needs::TwoPageView || self.active.and_then(|i| self.views.get(i)).is_some_and(crate::DocView::cover_applies)) && match spec.id { @@ -272,18 +286,6 @@ impl PdfCraftApp { } fn execute_unguarded(&mut self, ctx: &egui::Context, id: &str) -> bool { - // In Organize the clipboard commands are the picked pages' (the catalog enables them as - // `page.copy`, `page.cut` and `page.paste`). - let organize = self.active.and_then(|i| self.views.get(i)).is_some_and(|v| v.organize); - let page_command = match id { - "edit.copy" => Some("page.copy"), - crate::menus::CUT => Some("page.cut"), - crate::menus::PASTE => Some("page.paste"), - _ => None, - }; - if organize && let Some(page_command) = page_command { - return self.execute_unguarded(ctx, page_command); - } // Paste is the framework's clipboard command, not a registered one: the pages take what // the clipboard holds (objects, a picture or comment text). if id == crate::menus::PASTE { diff --git a/crates/ui-egui/src/commands/catalog.rs b/crates/ui-egui/src/commands/catalog.rs index 5a2443e310..70f6cbe9c9 100644 --- a/crates/ui-egui/src/commands/catalog.rs +++ b/crates/ui-egui/src/commands/catalog.rs @@ -40,6 +40,10 @@ const CATALOG_ONLY: &[(&str, &str, &str)] = &[ /// Commands whose chords and rows are the framework's clipboard commands. const FRAMEWORK_EDIT: &[&str] = &["edit.copy", "edit.paste"]; +/// Commands whose keys are the page view's own: it turns a page or spread on ⌘← / ⌘→ and ⌘Page Up / ⌘Page Down +/// itself, so a chord here would turn it twice. The menus still show the registry's shortcut. +const PAGE_VIEW_KEYS: &[&str] = &["view.next_page", "view.previous_page"]; + static CATALOG_WIN: OnceLock> = OnceLock::new(); static CATALOG_MAC: OnceLock> = OnceLock::new(); @@ -79,6 +83,9 @@ pub(crate) fn catalog(mac: bool) -> Result { } let mut chords: Vec = spec.shortcut_for(mac).and_then(menus::chord).into_iter().collect(); chords.extend(second_chords(spec.id)); + if PAGE_VIEW_KEYS.contains(&spec.id) { + chords.clear(); + } push(def, chords); } for (id, label, shortcut) in EXTRA.iter().filter(|(id, ..)| !FRAMEWORK_EDIT.contains(id)) { @@ -92,21 +99,18 @@ pub(crate) fn catalog(mac: bool) -> Result { } /// The chords a registry command takes beside its own shortcut: Alt+← / Alt+→ (⌥ on macOS) go back and forward -/// through the view history, as in Acrobat and browsers (#3632), and ⌘Page Up / ⌘Page Down turn a page as ⌘← / ⌘→ do. +/// through the view history, as in Acrobat and browsers (#3632). fn second_chords(id: &str) -> Vec { let alt = Mods { alt: true, ..Mods::default() }; - let cmd = Mods { cmd: true, ..Mods::default() }; match id { "view.previous_view" => vec![Chord::new(alt, Key::Left)], "view.next_view" => vec![Chord::new(alt, Key::Right)], - "view.previous_page" => vec![Chord::new(cmd, Key::PageUp)], - "view.next_page" => vec![Chord::new(cmd, Key::PageDown)], _ => Vec::new(), } } /// The catalog for this platform's chords, built once. -fn shared_catalog(mac: bool) -> Option { +pub(crate) fn shared_catalog(mac: bool) -> Option { let cell = if mac { &CATALOG_MAC } else { &CATALOG_WIN }; cell.get_or_init(|| catalog(mac).ok()).clone() } diff --git a/crates/ui-egui/src/dialogs/shortcuts.rs b/crates/ui-egui/src/dialogs/shortcuts.rs index a52442b613..f9d1cfff7e 100644 --- a/crates/ui-egui/src/dialogs/shortcuts.rs +++ b/crates/ui-egui/src/dialogs/shortcuts.rs @@ -24,13 +24,6 @@ fn fixed_rows(ctx: &egui::Context) -> Vec { let pair = |a, b| format!("{} / {}", key(a), key(b)); // Key names, translated where a catalog has them (not scanned as UI literals). let named = |k: &str| tl!(k).to_string(); - // Alt+← / Alt+→ (`canvas::shortcuts`): not a registered command, which has no Alt. - let alt_arrows = if mac { - "⌥← / ⌥→".to_owned() - } else { - let alt = crate::i18n::key_name("Alt"); - format!("{alt}+← / {alt}+→") - }; let scroll = crate::i18n::fmt(tl!("Zoom in / out (also pinch or {key}-scroll)"), &[("key", pdfcraft_engine::commands::Shortcut::command_name(mac))]); let first_last = format!("{} / {}, {}", crate::i18n::key_name("Home"), crate::i18n::key_name("End"), pair(FIRST_PAGE, LAST_PAGE)); @@ -48,7 +41,6 @@ fn fixed_rows(ctx: &egui::Context) -> Vec { (pair(ROTATE_CW, ROTATE_CCW), tl!("Rotate view").to_string()), (first_last, tl!("First / last page").to_string()), (format!("← / →, {}", pair(PAGE_PREV, PAGE_NEXT)), tl!("Previous / next page").to_string()), - (alt_arrows, format!("{} / {}", tl!("Previous view"), tl!("Next view"))), (named("V"), tl!("Select (V)").to_string()), (named("H / Space (hold)"), tl!("Hand (H)").to_string()), (crate::i18n::key_name("Delete").to_string(), tl!("Delete selected pages (Organize)").to_string()), @@ -66,8 +58,9 @@ impl PdfCraftApp { let mut options = Options::default(); options.editable = false; options.fixed = fixed_rows(ctx); - // PLAN: framework gap: `AppCatalog::defs` is `pub(crate)`, so the catalog's rows and scopes cannot reach `Keymap::new`; the dialog lists the fixed rows only until they are public - let keymap = Keymap::new(Vec::new(), Scopes::new(), Platform::current()); + // The catalog the keys run on, in the app scope; the page view's own keys are the fixed rows. + let defs = crate::commands::catalog::shared_catalog(crate::commands::mac_shortcuts(ctx)).map(|c| c.defs().to_vec()).unwrap_or_default(); + let keymap = Keymap::new(defs, Scopes::new(), Platform::current()); self.shortcuts = Some(ShortcutsSession { state: DialogState::new(), keymap, options }); } diff --git a/crates/ui-egui/src/workflows/js_dialogs.rs b/crates/ui-egui/src/workflows/js_dialogs.rs index e023fbad6e..cf85fb0e6f 100644 --- a/crates/ui-egui/src/workflows/js_dialogs.rs +++ b/crates/ui-egui/src/workflows/js_dialogs.rs @@ -140,14 +140,15 @@ fn document_scripts(app: &mut PdfCraftApp, ui: &mut egui::Ui, open: &mut bool, d let before = scripts.iter().position(|(n, _)| *n == draft.name); let mut selection = before.map_or_else(Selection::default, Selection::single); let source = ScriptRows(scripts.len()); - let out = List::new(tl!("Document JavaScripts")).select(SelectMode::Single).selection(Bind::bound(&mut selection)).show_items( - ui, - &source, - &mut |&at, icx| { + // A short list that scrolls its own rows, above the script. + let out = List::new(tl!("Document JavaScripts")) + .select(SelectMode::Single) + .selection(Bind::bound(&mut selection)) + .max_rows(5) + .show_items(ui, &source, &mut |&at, icx| { let name = scripts.get(at).map(|(n, _)| n.clone()).unwrap_or_default(); ListRow::new(name).striped(icx.at % 2 == 1) - }, - ); + }); // Only the pass's own pick copies; a drained event list is empty on a second pass. if out.events.iter().any(|e| !matches!(e, CollectionEvent::Column(_))) && selection.lead != before { if let Some((name, script)) = selection.lead.and_then(|at| scripts.get(at)) { diff --git a/crates/ui-egui/tests/it/view.rs b/crates/ui-egui/tests/it/view.rs index 530f61b9cb..3c0941d8d2 100644 --- a/crates/ui-egui/tests/it/view.rs +++ b/crates/ui-egui/tests/it/view.rs @@ -438,17 +438,21 @@ const EASED: [&str; 2] = ["system", "on"]; #[test] fn a_wheel_notch_scrolls_at_once_with_animation_effects_off() { - // Eased, egui spreads a notch over about a quarter of a second. At once, the page moves the - // notch's whole distance in one frame. + // Eased, the page view spreads a notch over several frames. At once, the page moves the notch's + // whole distance in one frame. let notch = pdfcraft_ui_egui::scroll_speed::ScrollSpeed::default().wheel_line(); + // The first frame the page stands the whole notch further on. + let arrives = |moved: &[f32]| moved.iter().position(|y| (y - notch).abs() < 0.5).unwrap_or(moved.len()); + let mut at_once = 0; for effects in AT_ONCE { let moved = frames_after_a_notch(effects, false); // The frame the notch arrives in scrolls; the next one draws the page where it stays. assert!(moved[2..].iter().all(|y| (y - notch).abs() < 0.5), "{effects}: one notch is {notch} points, all at once: {moved:?}"); + at_once = at_once.max(arrives(&moved)); } for effects in EASED { let moved = frames_after_a_notch(effects, false); - assert!(moved[2] < notch * 0.75, "{effects}: egui eases the notch: {moved:?}"); + assert!(arrives(&moved) > at_once + 1, "{effects}: the notch eases over more frames than at once ({at_once}): {moved:?}"); assert!((moved[39] - notch).abs() < 1.0, "{effects}: easing changes how long a notch takes, not how far it goes: {moved:?}"); } } @@ -1002,6 +1006,11 @@ fn from_viewport_corner(h: &Harness<'static, PdfCraftApp>, page: usize, fx: f32, egui::pos2(r.min.x + fx * r.width(), r.min.y + fy * r.height()) - vp.min } +/// The side gutter the page view keeps clear (the spacing token); a destination's left lands past it (L-245). +fn side_gutter(h: &Harness<'static, PdfCraftApp>) -> f32 { + h.state().views[0].spacing.as_ref().expect("laid out").side as f32 +} + #[test] fn bookmark_destinations_scroll_to_their_position() { use egui_kittest::kittest::Queryable; @@ -1024,7 +1033,8 @@ fn bookmark_destinations_scroll_to_their_position() { let v = &h.state().views[0]; assert_eq!((v.current(), v.fit(), v.zoom()), (1, Fit::None, 3.0)); let d = from_viewport_corner(&h, 1, 0.25, 0.5); - assert!((d.x - 70.0).abs() < 2.0 && d.y.abs() < 2.0, "the destination point is at the window's top-left: {d:?}"); + let side = side_gutter(&h); + assert!((d.x - side).abs() < 2.0 && d.y.abs() < 2.0, "the destination point is at the window's top-left, past the gutter {side}: {d:?}"); // Unusable operands are read as null, which keeps the reader's place in user space: y 300 // was at the window's top on page 2 (its crop box starts at y 100), so on page 3 (crop from @@ -1078,7 +1088,8 @@ fn a_link_without_a_position_keeps_the_place_on_the_next_page() { assert_eq!((h.state().views[0].current(), h.state().views[0].zoom()), (0, 4.0)); let (fx, fy) = (40.0 / 300.0, 40.0 / 400.0); let d = from_viewport_corner(&h, 0, fx, fy); - assert!((d.x - 70.0).abs() < 2.0 && d.y.abs() < 2.0, "(40, 360) is at the window's top-left: {d:?}"); + let side = side_gutter(&h); + assert!((d.x - side).abs() < 2.0 && d.y.abs() < 2.0, "(40, 360) is at the window's top-left, past the gutter {side}: {d:?}"); let r = rect(&h, 0).expect("page 1"); let at = egui::pos2(r.min.x + r.width() * (100.0 / 300.0), r.min.y + r.height() * (1.0 - 335.0 / 400.0)); @@ -1090,7 +1101,7 @@ fn a_link_without_a_position_keeps_the_place_on_the_next_page() { let v = &h.state().views[0]; assert_eq!((v.current(), v.zoom()), (1, 4.0), "the link goes to page 2 at the same zoom"); let d = from_viewport_corner(&h, 1, fx, fy); - assert!((d.x - 70.0).abs() < 2.0 && d.y.abs() < 2.0, "page 2 shows the same place, not its top: {d:?}"); + assert!((d.x - side).abs() < 2.0 && d.y.abs() < 2.0, "page 2 shows the same place, not its top: {d:?}"); } /// Two pages with a text field on each and a non-embedded Helvetica. diff --git a/crates/ui-egui/tests/it/viewer.rs b/crates/ui-egui/tests/it/viewer.rs index 75fb1cac3e..13810f0308 100644 --- a/crates/ui-egui/tests/it/viewer.rs +++ b/crates/ui-egui/tests/it/viewer.rs @@ -175,8 +175,11 @@ fn alt_arrows_go_back_and_forward_through_the_view_history() { h.ctx.set_os(egui::os::OperatingSystem::Nix); assert!(h.execute("help.shortcuts")); h.run_steps(3); - h.get_by_label("Alt+← / Alt+→"); - h.get_by_label("Previous view / Next view"); + // The keys are the history commands' own bindings, listed with the catalog's rows; the search + // brings the row into the list. + h.get_by_label("Search:").type_text("Previous view"); + h.run_steps(3); + assert!(h.query_all_by_label_contains("Previous view: Alt+").next().is_some(), "Previous view is listed with its Alt chord"); } #[test]