app red 5 (g3) (swarm/red5); committed by the lead

This commit is contained in:
Dylan M. Taylor
2026-11-18 23:06:26 -05:00
parent a28496de88
commit 91ccc09c88
5 changed files with 83 additions and 58 deletions
+2 -2
View File
@@ -233,9 +233,9 @@ pub const COMMANDS: &[CommandSpec] = &[
// and adds their further default chords.
c("view.zoom.in", "Zoom in", None, Some(Shortcut::cmd("+")), Document, "zoom_in"),
c("view.zoom.out", "Zoom out", None, Some(Shortcut::cmd("−")), Document, "zoom_out"),
c("view.zoom.page_level", "Page level zoom", None, Some(Shortcut::cmd("0")), Document, "maximize_2"),
c("view.zoom.page_level", "Zoom to page level", None, Some(Shortcut::cmd("0")), Document, "maximize_2"),
c("view.zoom.actual_size", "Actual size", None, Some(Shortcut::cmd("1")), Document, "scan"),
c("view.zoom.fit_width", "Fit width", None, Some(Shortcut::cmd("2")), Document, "move-horizontal"),
c("view.zoom.fit_width", "Fit to width", None, Some(Shortcut::cmd("2")), Document, "move-horizontal"),
c("view.rotate.cw", "Rotate view clockwise", None, Some(Shortcut::cmd_shift("+")), Document, "rotate_cw"),
c("view.rotate.ccw", "Rotate view counterclockwise", None, Some(Shortcut::cmd_shift("−")), Document, "rotate_ccw"),
c("view.first_page", "First page", None, Some(Shortcut::cmd_shift("Up")), Document, "chevrons_left"),
+37 -34
View File
@@ -94,29 +94,9 @@ impl PdfCraftApp {
}
}
"form.calculation_order.back" => self.left = crate::LeftPanel::Tool("form"),
"view.zoom.actual_size"
| "view.zoom.page_level"
| "view.zoom.fit_width"
| "view.zoom.fit_height"
| "view.zoom.in"
| "view.zoom.out"
| "view.rotate.cw"
| "view.rotate.ccw" => {
use crate::canvas::Fit;
"view.zoom.fit_height" => {
if let Some(v) = active.and_then(|i| self.views.get_mut(i)) {
match id {
"view.zoom.actual_size" => {
v.view.fit = Fit::None;
v.view.zoom = 1.0;
}
"view.zoom.page_level" => v.view.fit = Fit::Page,
"view.zoom.fit_width" => v.view.fit = Fit::Width,
"view.zoom.fit_height" => v.view.fit = Fit::Height,
"view.zoom.in" => v.view.zoom_step(true),
"view.zoom.out" => v.view.zoom_step(false),
"view.rotate.cw" => v.view.rotation = (v.view.rotation + 90) % 360,
_ => v.view.rotation = (v.view.rotation + 270) % 360,
}
v.view.fit = crate::canvas::Fit::Height;
}
}
"view.fit_toggle" => {
@@ -126,18 +106,6 @@ impl PdfCraftApp {
v.view.fit = fit;
}
}
"view.first_page" | "view.last_page" | "view.next_page" | "view.previous_page" => {
if let Some(v) = active.and_then(|i| self.views.get_mut(i)) {
let (current, last) = (v.current(), v.page_count().saturating_sub(1));
let page = match id {
"view.first_page" => 0,
"view.last_page" => last,
"view.next_page" => current.saturating_add(1).min(last),
_ => current.saturating_sub(1),
};
v.go_to_page(page);
}
}
"view.dock_side" => {
let edge = if crate::side_panels::state(self)["tools_side"] == "right" { "left" } else { "right" };
if let Err(e) = crate::side_panels::command(self, false, &serde_json::json!({ "panel": "tools", "edge": edge })) {
@@ -425,6 +393,41 @@ impl PdfCraftApp {
}
}
"view.palette" => self.palette_open = !self.palette_open,
"view.zoom.actual_size"
| "view.zoom.page_level"
| "view.zoom.fit_width"
| "view.zoom.in"
| "view.zoom.out"
| "view.rotate.cw"
| "view.rotate.ccw" => {
use crate::canvas::Fit;
if let Some(v) = active.and_then(|i| self.views.get_mut(i)) {
match id {
"view.zoom.actual_size" => {
v.view.fit = Fit::None;
v.view.zoom = 1.0;
}
"view.zoom.page_level" => v.view.fit = Fit::Page,
"view.zoom.fit_width" => v.view.fit = Fit::Width,
"view.zoom.in" => v.view.zoom_step(true),
"view.zoom.out" => v.view.zoom_step(false),
"view.rotate.cw" => v.view.rotation = (v.view.rotation + 90) % 360,
_ => v.view.rotation = (v.view.rotation + 270) % 360,
}
}
}
"view.first_page" | "view.last_page" | "view.next_page" | "view.previous_page" => {
if let Some(v) = active.and_then(|i| self.views.get_mut(i)) {
let (current, last) = (v.current(), v.page_count().saturating_sub(1));
let page = match id {
"view.first_page" => 0,
"view.last_page" => last,
"view.next_page" => current.saturating_add(1).min(last),
_ => current.saturating_sub(1),
};
v.go_to_page(page);
}
}
"view.layout.single" | "view.layout.two_up" => {
if let Some(v) = active.and_then(|i| self.views.get_mut(i)) {
v.view.display = if id == "view.layout.single" { PageDisplay::Single } else { PageDisplay::TwoUp };
+2 -1
View File
@@ -475,7 +475,8 @@ fn the_open_recent_menu_lists_files_and_opens_one() {
let path = path.to_string_lossy().into_owned();
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe({
let path = path.clone();
move |_cc| {
move |cc| {
crate::support::install_runtime(&cc.egui_ctx);
let mut app = new_app();
app.set_option(&egui::Context::default(), "language", "en").unwrap();
app.open_bytes(&egui::Context::default(), "doc.pdf", None, fixture(3)).unwrap();
+2 -1
View File
@@ -108,7 +108,8 @@ fn the_longest_list_scrolls_in_the_smallest_window_down_to_clear() {
let files: Vec<String> = (0..50).map(|n| format!("{n}.pdf")).collect();
let mut h = Harness::builder().with_size(egui::vec2(1000.0, 520.0)).build_eframe({
let files = files.clone();
move |_cc| {
move |cc| {
crate::support::install_runtime(&cc.egui_ctx);
let mut app = app_with(&files.iter().map(String::as_str).collect::<Vec<_>>());
app.recent_limit = 50;
app.open_bytes(&egui::Context::default(), "doc.pdf", None, PDF.to_vec()).unwrap();
+40 -20
View File
@@ -67,6 +67,21 @@ fn choose_in_documents_preferences(h: &mut Harness<'static, PdfCraftApp>, label:
h.run_steps(3);
}
/// Picks `option` in the Preferences choice row `row` on the Documents and view page and applies it with OK, as a
/// user does: the row is a select, whose options show once it is opened.
fn pick_in_documents_preferences(h: &mut Harness<'static, PdfCraftApp>, row: &str, option: &str) {
h.get_by_label("Documents and view").click();
h.run_steps(3);
h.get_by_role_and_label(egui::accesskit::Role::ComboBox, row).scroll_to_me();
h.run_steps(4);
h.get_by_role_and_label(egui::accesskit::Role::ComboBox, row).click();
h.run_steps(3);
h.get_all_by_label(option).last().unwrap_or_else(|| panic!("the {option:?} option is on screen")).click();
h.run_steps(2);
h.get_by_label("OK").click();
h.run_steps(3);
}
fn sidebar_key(h: &mut Harness<'static, PdfCraftApp>, key: Key, modifiers: Modifiers) {
h.event(egui::Event::ModifiersChanged(modifiers));
for pressed in [true, false] {
@@ -771,7 +786,7 @@ fn preferences_set_the_default_zoom() {
let mut h = harness(&[]);
assert!(h.execute("app.preferences"));
h.run_steps(3);
choose_in_documents_preferences(&mut h, "Zoom to page level");
pick_in_documents_preferences(&mut h, "Default zoom", "Zoom to page level");
assert!(h.execute("create.blank"));
assert_eq!(h.state().views[1].fit(), pdfcraft_ui_egui::canvas::Fit::Page);
}
@@ -1894,7 +1909,7 @@ fn sidebar_collapse_and_resize_preserves_scroll_position() {
}
/// Synthetic unequal-height spreads, generated without font or image assets.
fn final_spread_at_scroll_end(heights: &[u32], cover: bool) -> (Vec<(usize, egui::Rect)>, egui::Rect) {
fn final_spread_at_scroll_end(heights: &[u32], cover: bool) -> (Vec<(usize, egui::Rect)>, egui::Rect, f32) {
let kids = (0..heights.len()).map(|i| format!("{} 0 R", i + 3)).collect::<Vec<_>>().join(" ");
let mut pdf = format!(
"%PDF-1.7\n1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj\n2 0 obj << /Type /Pages /Kids [{kids}] /Count {} >> endobj\n",
@@ -1930,18 +1945,19 @@ fn final_spread_at_scroll_end(heights: &[u32], cover: bool) -> (Vec<(usize, egui
let last = heights.len() - 1;
let first = if cover { last - (last + 1) % 2 } else { last - last % 2 };
let pages = (first..=last).map(|page| (page, view.page_screen_rect(page).expect("final spread is visible"))).collect();
(pages, view.viewport_rect())
let margin = view.spacing.expect("the pages were laid out").margin as f32;
(pages, view.viewport_rect(), margin)
}
fn assert_final_spread_bottom_reachable(heights: &[u32], cover: bool) {
let (pages, viewport) = final_spread_at_scroll_end(heights, cover);
let (pages, viewport, margin) = final_spread_at_scroll_end(heights, cover);
let bottom = pages.iter().map(|(_, rect)| rect.bottom()).fold(0.0_f32, f32::max);
assert!(
bottom <= viewport.bottom() + 1.0,
"final spread remains below the viewport: heights={heights:?}, cover={cover}, pages={pages:?}, viewport={viewport:?}"
);
// The maximum-height page reaches the bottom margin after the scroll offset settles.
assert!((viewport.bottom() - bottom - 28.0).abs() < 1.0, "scroll end leaves the bottom margin: pages={pages:?}, viewport={viewport:?}");
assert!((viewport.bottom() - bottom - margin).abs() < 1.0, "scroll end leaves the bottom margin: pages={pages:?}, viewport={viewport:?}");
}
#[test]
@@ -2179,24 +2195,24 @@ fn the_pages_panel_tools_act_on_the_selected_pages() {
let mut h = harness(&[("panel", "pages")]);
let id = h.state().views[0].id;
let rotations = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(id).unwrap().info.pages.iter().map(|p| p.rotation).collect::<Vec<_>>();
// The panel's Page tools menu, on the right-hand side of the window.
let tool = |h: &mut Harness<'static, PdfCraftApp>, label: &str| {
// The panel's Page tools menu, on the right-hand side of the window: its rows are the page commands.
let tool = |h: &mut Harness<'static, PdfCraftApp>, command: &str| {
h.get_all_by_label("Panel Menu").find(|n| n.rect().left() > 1000.0).expect("Panel Menu in the Pages panel").click();
h.run_steps(2);
h.get_by_label(label).click();
h.get_by_label(pdfcraft_engine::commands::command(command).expect("a page command").label).click();
h.run_steps(3);
};
h.state_mut().views[0].select_pages(&[1, 2]);
h.run_steps(2);
tool(&mut h, "Rotate the selected pages clockwise");
tool(&mut h, "page.rotate");
assert_eq!(rotations(&h), [0, 90, 90], "pages 2 and 3, the selection");
tool(&mut h, "Rotate the selected pages counterclockwise");
tool(&mut h, "page.rotate_ccw");
assert_eq!(rotations(&h), [0, 0, 0]);
h.state_mut().views[0].select_pages(&[0]);
h.run_steps(2);
tool(&mut h, "Delete the selected pages");
tool(&mut h, "page.delete");
assert_eq!(h.state().session.get(id).unwrap().info.pages.len(), 2, "page 1 deleted");
tool(&mut h, "Insert a blank page after the selection");
tool(&mut h, "page.insert_blank");
assert_eq!(h.state().session.get(id).unwrap().info.pages.len(), 3);
h.execute("edit.undo");
h.run_steps(2);
@@ -2234,19 +2250,19 @@ fn the_pages_panel_tools_insert_from_a_file_and_extract() {
h.run_steps(8);
let id = h.state().views[0].id;
let count = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(id).unwrap().info.pages.len();
let tool = |h: &mut Harness<'static, PdfCraftApp>, label: &str| {
let tool = |h: &mut Harness<'static, PdfCraftApp>, command: &str| {
h.get_all_by_label("Panel Menu").find(|n| n.rect().left() > 1000.0).expect("Panel Menu in the Pages panel").click();
h.run_steps(2);
h.get_by_label(label).click();
h.get_by_label(pdfcraft_engine::commands::command(command).expect("a page command").label).click();
h.run_steps(3);
};
assert_eq!(count(&h), 3);
h.state_mut().views[0].select_pages(&[0]);
tool(&mut h, "Insert pages from a file after the selection…");
tool(&mut h, "page.insert");
assert!(crate::support::step_until(&mut h, |h| count(h) == 6), "the picked file's three pages are inserted");
h.state_mut().views[0].select_pages(&[1, 2]);
tool(&mut h, "Extract the selected pages…");
tool(&mut h, "page.extract");
assert!(h.state().dialogs.is_open::<craft::ui::patterns::form_dialogs::HostedParamDialog>(), "Extract opens for the selection");
h.get_by_label("Extract pages as separate files").click();
h.run_steps(2);
@@ -2278,11 +2294,15 @@ fn the_pages_panel_tools_are_off_without_page_editing_permission() {
let i = h.state().active.unwrap();
let id = h.state().views[i].id;
assert!(!h.state().session.get(id).unwrap().allows_assembly());
let tools = h.get_all_by_label("Panel Menu").find(|n| n.rect().left() > 1000.0).expect("Page tools");
assert!(tools.accesskit_node().is_disabled(), "Page tools is greyed out");
tools.click();
// The panel's menu also holds the dock's rows, so it opens; its page tools are greyed out.
h.get_all_by_label("Panel Menu").find(|n| n.rect().left() > 1000.0).expect("Panel Menu in the Pages panel").click();
h.run_steps(3);
let label = |command: &str| pdfcraft_engine::commands::command(command).expect("a page command").label;
for command in ["page.insert_blank", "page.insert", "page.rotate_ccw", "page.rotate", "page.delete"] {
assert!(h.get_by_label(label(command)).accesskit_node().is_disabled(), "{command} is greyed out");
}
h.get_by_label(label("page.delete")).click();
h.run_steps(3);
assert!(h.query_by_label("Delete the selected pages").is_none(), "its menu doesn't open");
assert_eq!(h.state().session.get(id).unwrap().info.pages.len(), 3);
}