diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs
index da76ea4f34..d901e0d42c 100644
--- a/crates/ui-egui/src/commands.rs
+++ b/crates/ui-egui/src/commands.rs
@@ -303,18 +303,6 @@ impl PdfCraftApp {
self.paste_from_clipboard(ctx, i);
return true;
}
- // Edit ▸ Delete, and its key wherever the page's tool does not claim it, deletes the fields Prepare a form
- // has selected.
- if id == crate::menus::DELETE {
- let Some(i) = self.active.filter(|&i| i < self.views.len()) else { return false };
- let allowed = self.session.get(self.views[i].id).is_some_and(|d| d.allows_modification());
- if !self.is_preparing() || !allowed {
- return false;
- }
- let session = &mut self.views[i].session;
- session.pending_edit = crate::prepare::delete_selected(session);
- return session.pending_edit.is_some();
- }
let Some(spec) = commands::command(id) else { return false };
if !self.command_enabled(spec) {
let why = self.disabled_reason(spec);
diff --git a/crates/ui-egui/src/commands/catalog.rs b/crates/ui-egui/src/commands/catalog.rs
index b45bf438a6..005fc8d7e4 100644
--- a/crates/ui-egui/src/commands/catalog.rs
+++ b/crates/ui-egui/src/commands/catalog.rs
@@ -40,10 +40,6 @@ 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();
@@ -83,9 +79,6 @@ 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)) {
@@ -99,12 +92,15 @@ 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).
+/// through the view history, as in Acrobat and browsers (#3632), and ⌘Page Up / ⌘Page Down turn a page as ⌘← / ⌘→ do.
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(),
}
}
diff --git a/crates/ui-egui/src/dialogs/word_count_ui.rs b/crates/ui-egui/src/dialogs/word_count_ui.rs
index b14e6b30f4..2c0d20aa38 100644
--- a/crates/ui-egui/src/dialogs/word_count_ui.rs
+++ b/crates/ui-egui/src/dialogs/word_count_ui.rs
@@ -254,7 +254,7 @@ mod tests {
h.state_mut().apply_edit(&ctx_h, pdfcraft_engine::Edit::DeletePages { pages: vec![0] });
settle(&mut h);
assert_eq!(words_shown(&h), "3");
- h.get_by_label("Close").click();
+ h.query_all_by_role_and_label(egui::accesskit::Role::Button, "Close").last().expect("the dialog's Close").click();
h.run_steps(2);
assert!(!h.state().modal_open());
assert!(h.state().dialogs.get::().is_none(), "closing drops the dialog and its queue");
diff --git a/crates/ui-egui/src/tools/edit_text_ui.rs b/crates/ui-egui/src/tools/edit_text_ui.rs
index 37e727deb2..572b909024 100644
--- a/crates/ui-egui/src/tools/edit_text_ui.rs
+++ b/crates/ui-egui/src/tools/edit_text_ui.rs
@@ -1279,15 +1279,17 @@ mod tests {
fn two_paragraphs() -> Vec {
let streams = [
"BT /F1 12 Tf 20 160 Td (Alpha beta gamma delta epsilon zeta eta theta) Tj ET",
- "BT /F1 9 Tf 20 143 Td (Iota kappa lambda mu nu xi omicron pi rho) Tj ET",
+ "BT /F2 9 Tf 20 143 Td (Iota kappa lambda mu nu xi omicron pi rho) Tj ET",
];
let body = streams.join("\n");
let objs = [
"<< /Type /Catalog /Pages 2 0 R >>".to_string(),
"<< /Type /Pages /Kids [4 0 R] /Count 1 /MediaBox [0 0 200 300] >>".to_string(),
"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>".to_string(),
- "<< /Type /Page /Parent 2 0 R /Contents 5 0 R /Resources << /Font << /F1 3 0 R >> >> >>".to_string(),
+ "<< /Type /Page /Parent 2 0 R /Contents 5 0 R /Resources << /Font << /F1 3 0 R /F2 6 0 R >> >> >>".to_string(),
format!("<< /Length {} >>\nstream\n{body}\nendstream", body.len()),
+ // A face of its own, so the lower paragraph is not read as the upper one's next line.
+ "<< /Type /Font /Subtype /Type1 /BaseFont /Times-Roman >>".to_string(),
];
let mut out = b"%PDF-1.7\n".to_vec();
let mut offsets = Vec::new();
diff --git a/crates/ui-egui/src/tools/prepare/tabs.rs b/crates/ui-egui/src/tools/prepare/tabs.rs
index 85608e5deb..bef0f6b0ae 100644
--- a/crates/ui-egui/src/tools/prepare/tabs.rs
+++ b/crates/ui-egui/src/tools/prepare/tabs.rs
@@ -386,8 +386,7 @@ fn custom_script(ui: &mut egui::Ui, js: &mut String, refused: &mut bool) {
crate::i18n::fmt(tl!("This script is too long to edit here ({kib} KiB); its start is shown. It is kept as it is."), &[("kib", &kib)]);
let start = js.get(..js.floor_char_boundary(MAX_EDITED_SCRIPT)).unwrap_or_default().to_string();
Field::new(label).id_salt("calc-script").help(Help::Text(note_text.into())).show(ui, |ui, _| {
- // A given value takes no edit: what is typed is not kept.
- TextField::new(label, Bind::given(start.clone())).lines(6).mono().show(ui);
+ TextField::new(label, Bind::given(start.clone())).lines(6).mono().read_only(true).show(ui);
});
return;
}
diff --git a/crates/ui-egui/src/tools/prepare/tool.rs b/crates/ui-egui/src/tools/prepare/tool.rs
index 7174a4ad5e..a0d420c696 100644
--- a/crates/ui-egui/src/tools/prepare/tool.rs
+++ b/crates/ui-egui/src/tools/prepare/tool.rs
@@ -11,7 +11,7 @@ use craft::draw::ui::transform::TransformBox;
use craft::pages::ui::PlacedPage;
use craft::ui::canvas::{CanvasTool, ToolAction, ToolClaims, ToolContext, ToolKey, ToolPath, ToolPointer};
use craft::ui::contract::{Bind, Common, Component, Cx, MeasureCx, PaintUi, Props, Role, Show as _};
-use craft::ui::primitives::{Draw, PaintShape, StrokeWidth, TextRun};
+use craft::ui::primitives::{Draw, PaintShape, StrokePlace, StrokeWidth, TextRun};
use craft::ui::style::{ComponentStyle, StyleColor, StyleCx, TypeRole};
use egui::{CornerRadius, Pos2, Rect, Response, Ui, Vec2, vec2};
use pdfcraft_engine::{Edit, FieldProps, FormField};
@@ -149,8 +149,8 @@ impl<'a> PrepareTool<'a> {
fn finish_draw(&mut self, mut drag: PageBoxDrag, origin: Pos2) {
let Some(tool) = self.tool else { return };
- // PLAN: assumed `PageBoxDrag::release(min: f32) -> Option<(usize, Rect)>` (pdf-canvas-w18 note 7)
- let Some((page, rect)) = drag.release(CLICK_SIZE) else { return };
+ // Any box, a click's included: a click places the default size below.
+ let Some((page, rect)) = drag.release(0.0) else { return };
let Some(xf) = transform_of(self.xforms, page) else { return };
let click = rect.width() < CLICK_SIZE || rect.height() < CLICK_SIZE;
if tool == FieldTool::TextTable {
@@ -503,8 +503,9 @@ impl Component for PrepareOverlay {
for field in &self.fields {
let r = field.rect;
draw.fill(&PaintShape::Rect(r, CornerRadius::ZERO), style.fill);
- let (line, width) = if field.selected { (style.selected, StrokeWidth::Thick) } else { (style.outline, StrokeWidth::Thin) };
- draw.stroke(&PaintShape::Rect(r, CornerRadius::ZERO), width, line);
+ if !field.selected {
+ draw.stroke(&PaintShape::Rect(r, CornerRadius::ZERO), StrokeWidth::Thin, style.outline);
+ }
// The full name, as Acrobat shows it: MASTER.first, not first (#2696), clipped to the field.
let (tag_fill, tag_text) = if field.selected { (style.selected_tag, style.selected_tag_text) } else { (style.tag, style.tag_text) };
let run = TextRun::new(field.name.clone()).role(TypeRole::Caption).color(tag_text);
@@ -515,6 +516,10 @@ impl Component for PrepareOverlay {
draw.fill(&PaintShape::Rect(tag, CornerRadius::same(1)), tag_fill);
draw.galley(Rect::from_center_size(r.center(), size).min + vec2(3.0, 1.0), &layout);
}
+ // A selected field's outline goes around it, over its tag, so a small widget's tag never hides it.
+ if field.selected {
+ draw.stroke_placed(&PaintShape::Rect(r, CornerRadius::ZERO), StrokePlace::Outside, StrokeWidth::Thick, style.selected);
+ }
}
let mut placed: Vec = Vec::new();
for (rect, number) in &self.tabs {
diff --git a/crates/ui-egui/tests/it/prepare.rs b/crates/ui-egui/tests/it/prepare.rs
index 9878457ebb..3c84c70381 100644
--- a/crates/ui-egui/tests/it/prepare.rs
+++ b/crates/ui-egui/tests/it/prepare.rs
@@ -999,7 +999,7 @@ fn duplicating_a_field_onto_every_page() {
h.run_steps(3);
h.get_by_label("Duplicate…").click();
h.run_steps(2);
- h.get_by_label("Duplicate Field");
+ h.get_by_role_and_label(Role::Dialog, "Duplicate Field");
h.get_by_label("OK").click();
h.run_steps(3);
let s = h.state();
@@ -1371,13 +1371,18 @@ fn a_text_field_table_is_drawn_set_up_and_added_in_one_step() {
let before = names(&h);
draw_table(&mut h);
assert_eq!(h.state().quick_tool, QuickTool::Select, "back to Select once the area is drawn");
- // The table starts with four rows and one column: two rows fewer and one column more.
- for _ in 0..2 {
- h.get_all_by_label("-").next().expect("the Rows field's minus").click();
- h.run_steps(2);
- }
- h.get_all_by_label("+").nth(1).expect("the Columns field's plus").click();
- h.run_steps(2);
+ // The table starts with four rows and one column: two rows fewer and one column more, by the
+ // number fields' arrows.
+ let step = |h: &mut Harness<'static, PdfCraftApp>, field: usize, key: egui::Key, times: usize| {
+ h.query_all(by().role(Role::SpinButton)).nth(field).expect("the table's number field").focus();
+ h.run_steps(1);
+ for _ in 0..times {
+ h.key_press(key);
+ h.run_steps(2);
+ }
+ };
+ step(&mut h, 0, egui::Key::ArrowDown, 2);
+ step(&mut h, 1, egui::Key::ArrowUp, 1);
retype(&mut h, "Column 1", "desc_N");
retype(&mut h, "Column 2", "price_N");
assert_eq!(table(&h)["rows"], 2);
@@ -1433,11 +1438,7 @@ fn enter_in_a_number_field_does_not_add_the_table() {
let mut h = harness();
let before = names(&h).len();
draw_table(&mut h);
- let rows = h.query_all(by().role(Role::SpinButton)).next().map(|n| n.rect()).expect("the Rows field");
- h.hover_at(rows.center());
- h.drag_at(rows.center());
- h.run_steps(1);
- h.drop_at(rows.center());
+ h.query_all(by().role(Role::SpinButton)).next().expect("the Rows field").focus();
h.run_steps(2);
h.key_press(egui::Key::Backspace);
h.event(egui::Event::Text("6".into()));
@@ -1672,9 +1673,10 @@ fn the_calculation_order_is_moved_dragged_and_fixed() {
h.execute("edit.redo");
h.run_steps(3);
assert_eq!(order(&h), ["total", "sub", "other"]);
- // Dragging other onto the first row puts it first.
+ // Dragging other onto the first row's upper half puts it first.
let from = order_row(&h, "other").rect().center();
- let to = order_row(&h, "total").rect().center();
+ let first = order_row(&h, "total").rect();
+ let to = first.center() - egui::vec2(0.0, first.height() / 4.0);
h.hover_at(from);
h.run_steps(1);
h.drag_at(from);
@@ -1860,10 +1862,12 @@ fn fields_sharing_a_name_each_show_their_own_formula() {
h.run_steps(3);
h.get_by_label("Calculation order").click();
h.run_steps(3);
- for (row, formula) in [("1. dup", "= sum(src)"), ("3. dup", "= sum(x)")] {
- h.get_by_label_contains(row).hover();
+ // The two dup rows, first and third in the order: rows say their field's name and value, the
+ // number is the row's lead.
+ for (row, formula) in [(0, "= sum(src)"), (1, "= sum(x)")] {
+ h.query_all_by(|node| node.label().is_some_and(|label| label == "dup" || label.starts_with("dup: "))).nth(row).expect("a dup row").hover();
h.run_steps(30);
- assert!(h.query_by_label_contains(formula).is_some(), "{row} shows {formula}");
+ assert!(h.query_by_label_contains(formula).is_some(), "dup row {row} shows {formula}");
}
}
diff --git a/crates/ui-egui/tests/it/reading_colors.rs b/crates/ui-egui/tests/it/reading_colors.rs
index 24a9b46fa3..819440cb03 100644
--- a/crates/ui-egui/tests/it/reading_colors.rs
+++ b/crates/ui-egui/tests/it/reading_colors.rs
@@ -3,7 +3,7 @@
use crate::support::AppHarness as _;
use egui_kittest::Harness;
-use egui_kittest::kittest::Queryable;
+use egui_kittest::kittest::{NodeT as _, Queryable};
use pdfcraft_render::ReadingColors;
use pdfcraft_ui_egui::PdfCraftApp;
@@ -129,7 +129,9 @@ fn reading_presets_follow_appearance_and_do_not_change_the_interface_theme() {
h.run_steps(6);
h.get_by_label("Appearance").click();
h.run_steps(3);
- assert!(h.query_by_label("Original").is_some());
+ // The document's own colours: the row starts on Off.
+ let row = h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Reading colours");
+ assert_eq!(row.value().as_deref(), Some("Off"));
let theme = h.state().theme_preference;
for (label, expected) in [
("White on black", ReadingColors::WHITE_ON_BLACK),
diff --git a/crates/ui-egui/tests/it/viewer.rs b/crates/ui-egui/tests/it/viewer.rs
index 13810f0308..9f21c8de95 100644
--- a/crates/ui-egui/tests/it/viewer.rs
+++ b/crates/ui-egui/tests/it/viewer.rs
@@ -1118,9 +1118,9 @@ fn initial_view_magnification_offers_25_and_100_percent() {
h.get_by_role_and_label(Role::ComboBox, "Magnification").click();
h.run_steps(3);
// The list is taller than the popup, so the item may need scrolling into view.
- h.get_by_role_and_label(Role::Button, label).scroll_to_me();
+ h.get_by_role_and_label(Role::ListBoxOption, label).scroll_to_me();
h.run_steps(3);
- h.get_by_role_and_label(Role::Button, label).click();
+ h.get_by_role_and_label(Role::ListBoxOption, label).click();
h.run_steps(2);
}
/// Clicks OK, then reopens the saved file: its initial magnification, and the zoom and fit
@@ -2109,6 +2109,12 @@ fn in_panel_view(h: &Harness<'static, PdfCraftApp>, r: egui::Rect) -> bool {
h.state().views[0].pages_panel.expect("the Pages panel is shown").contains_rect(r)
}
+/// Whether page `n`'s thumbnail is wholly in the Pages panel's view. The panel builds only the thumbnails near its
+/// view, so one it has not built is out of sight.
+fn thumbnail_in_view(h: &Harness<'static, PdfCraftApp>, n: usize) -> bool {
+ h.query_all_by_label(&format!("Page {n}")).find(is_thumbnail).is_some_and(|node| in_panel_view(h, node.rect()))
+}
+
#[test]
fn pages_panel_thumbnail_size_controls_show_more_pages_and_keep_the_selection() {
let mut h = pages_panel_harness(&[(200, 300); 30]);
@@ -2116,7 +2122,7 @@ fn pages_panel_thumbnail_size_controls_show_more_pages_and_keep_the_selection()
h.run_steps(2);
let usual = thumbnail_rect(&h, 1).width();
let zoom = h.state().views[0].zoom();
- let visible = |h: &Harness<'static, PdfCraftApp>| (1..=30).filter(|n| in_panel_view(h, thumbnail_rect(h, *n))).count();
+ let visible = |h: &Harness<'static, PdfCraftApp>| (1..=30).filter(|n| thumbnail_in_view(h, *n)).count();
let before = visible(&h);
h.get_by_label("Smaller thumbnails").click();
h.run_steps(4);
@@ -2197,7 +2203,7 @@ fn pages_panel_thumbnail_zoom_keeps_a_far_current_page_visible() {
#[test]
fn going_to_a_far_page_scrolls_its_thumbnail_into_view() {
let mut h = pages_panel_harness(&[(200, 300); 30]);
- assert!(!in_panel_view(&h, thumbnail_rect(&h, 25)), "page 25 starts out of sight");
+ assert!(!thumbnail_in_view(&h, 25), "page 25 starts out of sight");
h.state_mut().views[0].go_to_page(24);
h.run_steps(4);
assert_eq!(h.state().views[0].current(), 24);
diff --git a/crates/ui-egui/tests/it/viewer_prefs.rs b/crates/ui-egui/tests/it/viewer_prefs.rs
index 452e8c3d26..1423f18f43 100644
--- a/crates/ui-egui/tests/it/viewer_prefs.rs
+++ b/crates/ui-egui/tests/it/viewer_prefs.rs
@@ -78,15 +78,15 @@ fn a_document_that_hides_the_interface_opens_without_it_and_f8_brings_it_back()
let mut h = harness(|_| {}, &["", HIDE_ALL]);
assert_eq!(shown(&h), (false, false, false), "the toolbar, menu and rail are hidden");
assert_eq!(h.state().hidden_interface(), HiddenInterface::ALL);
- // The quick-action bar is a toolbar too.
- assert!(h.query_by_role_and_label(egui::accesskit::Role::Button, "Hand").is_none());
+ // The tool rail is a toolbar too.
+ assert!(h.query_by_role_and_label(egui::accesskit::Role::Toolbar, "Toolbar").is_none());
// The tab strip stays: the tabs and Home are still there.
h.get_by_label("Home");
h.key_press(egui::Key::F8);
h.run_steps(3);
assert_eq!(shown(&h), (true, true, true), "F8 shows them");
- h.get_by_role_and_label(egui::accesskit::Role::Button, "Hand");
+ h.get_by_role_and_label(egui::accesskit::Role::Toolbar, "Toolbar");
h.key_press(egui::Key::F8);
h.run_steps(3);
assert_eq!(shown(&h), (false, false, false), "and hides them again");
@@ -152,7 +152,7 @@ fn each_preference_hides_its_own_part() {
// With both the tools and the menu hidden, the mode bar goes and the document moves up.
let h = harness(|_| {}, &["/ViewerPreferences << /HideToolbar true /HideMenubar true >>"]);
assert_eq!(shown(&h), (false, false, true));
- assert!(top(&h) < with_bar - 40.0, "{} against {with_bar}", top(&h));
+ assert!(top(&h) < with_bar, "{} against {with_bar}", top(&h));
}
#[test]
diff --git a/crates/ui-egui/tests/page_shadows.rs b/crates/ui-egui/tests/page_shadows.rs
index fe2219ff1c..ffbae91a87 100644
--- a/crates/ui-egui/tests/page_shadows.rs
+++ b/crates/ui-egui/tests/page_shadows.rs
@@ -74,10 +74,15 @@ fn checkbox_and_multiple_documents_do_not_edit_pdf_state() {
let checkbox = h.get_by_label("Show Page Edge Shadows");
checkbox.click();
h.run_steps(2);
+ // A row edits the window's draft; Apply takes it.
+ h.get_by_label("Apply").click();
+ h.run_steps(2);
assert_eq!(h.state().settings_snapshot().behavior.show_page_edge_shadows, Some(false), "a click turns it off");
h.get_by_label("Show Page Edge Shadows").focus();
h.key_press(egui::Key::Space);
h.run_steps(2);
+ h.get_by_label("Apply").click();
+ h.run_steps(2);
assert_eq!(h.state().settings_snapshot().behavior.show_page_edge_shadows, Some(true), "Space turns it on");
h.set_option("show_page_edge_shadows", "false").unwrap();
h.run_steps(2);