red10 g1: app red round 10 fixes

This commit is contained in:
Dylan M. Taylor
2026-11-19 21:12:35 -05:00
parent 177de584de
commit 7c7e66fed9
14 changed files with 162 additions and 108 deletions
+3
View File
@@ -799,6 +799,9 @@ impl PdfCraftApp {
// Dialogs and notices show in full screen too: a refused field value or a failed save must be seen.
dialogs::show(self, ui);
crate::notices::show(self, ui);
for view in &mut self.views {
crate::canvas::organize::finish_reveal(view, &ctx);
}
// Screenshots are issued only after a settled pass that really drew the window.
self.control_ui_pass(&ctx);
// Addresses `open_url` queued: the runtime opens them in the browser.
+40 -38
View File
@@ -51,27 +51,21 @@ impl PdfCraftApp {
false
}
/// Hands the pastes this frame's raw input carries to the clipboard, once per frame, so the
/// Paste command reads them. A frame's input is applied once, in the pass that receives it.
pub(crate) fn offer_pasted(&mut self, input: &egui::RawInput) {
let flavors: Vec<Flavor> = input
.events
.iter()
.filter_map(|event| match event {
egui::Event::Paste(text) => Some(Flavor::text(text)),
egui::Event::PasteImage(image) => {
let (width, height) = (u32::try_from(image.size[0]).ok()?, u32::try_from(image.size[1]).ok()?);
// The layout of an `RGBA8` flavour: width and height as little-endian words, then
// straight RGBA.
let mut data = Vec::with_capacity(8 + image.pixels.len() * 4);
data.extend_from_slice(&width.to_le_bytes());
data.extend_from_slice(&height.to_le_bytes());
data.extend(image.pixels.iter().flat_map(egui::Color32::to_srgba_unmultiplied));
Some(Flavor::new(RGBA8, data))
}
_ => None,
})
.collect();
/// Offer the content delivered with the fired paste in the frame that runs it.
pub(crate) fn offer_clip_content(&mut self, content: &craft::ui::runtime::commands::ClipContent) {
let mut flavors = Vec::new();
if let Some(text) = &content.text {
flavors.push(Flavor::text(text.as_ref()));
}
if let Some(image) = &content.image {
if let (Ok(width), Ok(height)) = (u32::try_from(image.size[0]), u32::try_from(image.size[1])) {
let mut data = Vec::new();
data.extend_from_slice(&width.to_le_bytes());
data.extend_from_slice(&height.to_le_bytes());
data.extend(image.pixels.iter().flat_map(egui::Color32::to_srgba_unmultiplied));
flavors.push(Flavor::new(RGBA8, data));
}
}
if !flavors.is_empty() {
self.clipboard.offer_paste(flavors);
}
@@ -114,44 +108,44 @@ impl PdfCraftApp {
/// Copy on the canvas: with objects selected in Edit a PDF, those; with no text selected, the
/// selected comments with their replies; else the text; else the selected image.
pub(crate) fn copy_from_canvas(&mut self, ctx: &egui::Context, i: usize) {
pub(crate) fn copy_from_canvas(&mut self, ctx: &egui::Context, i: usize) -> bool {
if self.views.get(i).is_some_and(|v| v.session.forms.focus.is_some() || v.organize) {
return;
return false;
}
// Objects selected together in Edit a PDF take the copy.
if self.quick_tool == QuickTool::EditText && self.views.get(i).is_some_and(|v| v.session.objects.count() > 0) {
self.copy_objects(ctx, i, false);
return;
return self.copy_objects(ctx, i, false);
}
// A selection across pages still being read has no text yet, but is selected all the
// same: its copy starts rather than copying the selected comments.
let text_selected =
self.views.get(i).is_some_and(|v| v.selection_waits_for_text().is_some() || v.selected_text().is_some_and(|t| !t.is_empty()));
if (text_selected || !self.copy_selected_comments(i))
&& !self.copy_selected_text(i)
&& let Some(sel) = self.views.get(i).and_then(|v| v.session.image_selection.clone())
&& let Some(id) = self.views.get(i).map(|v| v.id)
&& self.may_copy(id)
{
self.copy_page_image(sel.page, sel.index);
if !text_selected && self.copy_selected_comments(i) {
return true;
}
if self.copy_selected_text(i) || self.copy_picked_image(i) {
return true;
}
let Some(sel) = self.views.get(i).and_then(|v| v.session.image_selection.clone()) else { return false };
let Some(id) = self.views.get(i).map(|v| v.id) else { return false };
self.may_copy(id) && self.copy_page_image(sel.page, sel.index)
}
/// Cut on the canvas: objects selected in Edit a PDF, else the selected image.
pub(crate) fn cut_from_canvas(&mut self, ctx: &egui::Context, i: usize) {
pub(crate) fn cut_from_canvas(&mut self, ctx: &egui::Context, i: usize) -> bool {
if self.views.get(i).is_some_and(|v| v.session.forms.focus.is_some() || v.organize) {
return;
return false;
}
if self.quick_tool == QuickTool::EditText && self.views.get(i).is_some_and(|v| v.session.objects.count() > 0) {
self.copy_objects(ctx, i, true);
return;
return self.copy_objects(ctx, i, true);
}
if let Some(sel) = self.views.get(i).and_then(|v| v.session.image_selection.clone())
&& let Some(id) = self.views.get(i).map(|v| v.id)
&& self.may_copy(id)
{
self.cut_page_image(ctx, sel.page, sel.index);
return self.cut_page_image(ctx, sel.page, sel.index);
}
false
}
/// Paste on the canvas, in this order: the objects copied in Edit a PDF while the clipboard
@@ -427,7 +421,15 @@ mod review_tests {
/// One frame's paste events offered, then Paste run as its command; the images on page 1.
fn paste(app: &mut PdfCraftApp, events: Vec<egui::Event>) -> usize {
app.offer_pasted(&egui::RawInput { events, ..Default::default() });
let mut content = craft::ui::runtime::commands::ClipContent::default();
for event in events {
match event {
egui::Event::Paste(text) => content.text = Some(text.into()),
egui::Event::PasteImage(image) => content.image = Some(image),
_ => {}
}
}
app.offer_clip_content(&content);
assert!(app.execute(&egui::Context::default(), "edit.paste"));
app.session.get(app.views[0].id).unwrap().page_images(0).len()
}
+2 -4
View File
@@ -5,12 +5,10 @@ use craft::ui::shell::embed;
impl PdfCraftApp {
/// The app's part of [`eframe::App::raw_input_hook`], before egui reads the frame's input:
/// what the platform pasted goes to the clipboard service, then the runtime hands over what
/// it gathered since the last frame (the commands fired) and takes this frame's root values,
/// the runtime hands over what it gathered since the last frame (the commands fired) and takes this frame's root values,
/// command states and host. eframe calls the hook once per frame, before the first pass, so
/// a second pass of the same frame runs on what this call set and fires nothing twice.
pub(super) fn prepare_raw_input(&mut self, ctx: &egui::Context, raw: &mut egui::RawInput) {
self.offer_pasted(raw);
pub(super) fn prepare_raw_input(&mut self, ctx: &egui::Context, _raw: &mut egui::RawInput) {
self.set_title_bar_choice(ctx, self.title_bar_choice);
self.control_before_input(ctx);
embed::before_input(ctx, |output| {
+14 -1
View File
@@ -212,7 +212,10 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document,
};
let middle = if cfg!(target_os = "linux") { MiddleButton::AutoScroll } else { MiddleButton::Pan };
let current = view.view.current;
let reveal = view.grid_reveal.take();
let reveal = view.grid_reveal;
if reveal.is_some() {
cx.ui.ctx().data_mut(|data| data.insert_temp(organize_grid_id(view).with("reveal-drawn"), true));
}
let id = organize_grid_id(view);
// PLAN: assumed `PageThumbnails::invert_middle(bool)` beside `middle_button` (pdf-canvas-w6).
let out = PageThumbnails::new(tl!("Pages"), &pages, &mut view.selected, current, DataColor::new(egui::Color32::WHITE))
@@ -227,6 +230,7 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document,
.invert_middle(cx.invert_middle)
.reveal(reveal)
.show(cx.ui);
view.middle_scrolling = out.auto_scrolling;
// The menu is open from the request until a row runs or it is dismissed.
// PLAN: assumed the open anchor needs a remembered slot; egui's temp data keyed by the grid stands in for it.
@@ -277,3 +281,12 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document,
}
}
}
/// Retire a reveal only after the pass that drew it is known to have survived.
pub(crate) fn finish_reveal(view: &mut DocView, ctx: &egui::Context) {
let id = organize_grid_id(view).with("reveal-drawn");
let drawn = ctx.data_mut(|data| data.remove_temp::<bool>(id)).unwrap_or(false);
if drawn && !ctx.will_discard() {
view.grid_reveal = None;
}
}
+11 -13
View File
@@ -56,6 +56,9 @@ impl PdfCraftApp {
/// automation. The catalog's app-side handlers come first; every other id is a registered
/// command and goes through [`Self::execute`].
pub(crate) fn run_fired(&mut self, ctx: &egui::Context, fired: &Fired) {
if let Some(content) = &fired.pasted {
self.offer_clip_content(content);
}
let id = fired.command.id.as_str();
// The OCR Verify screen keeps the window's toolbars and owns F8 and Shift+F8 (the next
// and previous word to review), so they don't show or hide the interface there.
@@ -97,6 +100,9 @@ impl PdfCraftApp {
let id = fired.command.id.as_str();
let active = self.active;
match id {
crate::menus::QUIT => {
self.request_quit(ctx);
}
// The Combine list takes Select all and Delete while it shows, whatever has the focus
// there (a text field keeps them).
"edit.select_all" if self.combine_showing() => {
@@ -220,7 +226,9 @@ impl PdfCraftApp {
&& (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())
|| v.session.picked_image.is_some()
|| v.session.image_selection.is_some()
|| v.session.comments.primary().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 {
@@ -304,12 +312,10 @@ impl PdfCraftApp {
self.paste_from_clipboard(ctx, i);
return true;
}
// Copy and Cut take the objects selected together in Edit a PDF, as the catalog enables them for those.
if (id == "edit.copy" || id == crate::menus::CUT)
&& let Some(i) = self.active.filter(|&i| self.views.get(i).is_some_and(|v| !v.organize && v.session.objects.count() > 0))
&& self.quick_tool == crate::QuickTool::EditText
&& let Some(i) = self.active.filter(|&i| self.views.get(i).is_some_and(|v| !v.organize))
{
return self.copy_objects(ctx, i, id == crate::menus::CUT);
return if id == "edit.copy" { self.copy_from_canvas(ctx, i) } else { self.cut_from_canvas(ctx, i) };
}
let Some(spec) = commands::command(id) else { return false };
if !self.command_enabled(spec) {
@@ -748,14 +754,6 @@ impl PdfCraftApp {
self.quick_tool = crate::QuickTool::Snapshot;
self.notify_tr("Drag a rectangle around the area to copy");
}
"edit.copy" => {
let Some(i) = active else { return Some(false) };
// With no text selected, a picked picture is copied in its original format.
if self.views.get(i).is_some_and(|v| v.selected_text().is_none_or(|t| t.is_empty())) && self.copy_picked_image(i) {
return Some(true);
}
return Some(self.copy_selected_text(i));
}
"comment.copy" => {
let Some(i) = active else { return Some(false) };
return Some(self.copy_selected_comments(i));
+6 -2
View File
@@ -11,7 +11,7 @@ use craft::ui::runtime::commands::{
};
use pdfcraft_engine::commands::{self as engine, CommandSpec};
use crate::menus::{self, CUT, DELETE, DOCUMENT, EXTRA, NO_RECENT, PANEL, PANELS, PASTE, SELECT_ALL};
use crate::menus::{self, CUT, DELETE, DOCUMENT, EXTRA, NO_RECENT, PANEL, PANELS, PASTE, QUIT, SELECT_ALL};
use crate::{Mode, PdfCraftApp, QuickTool};
use craft::pages::PageDisplay;
use craft::theme::ModeChoice;
@@ -24,7 +24,7 @@ const CATALOG_ONLY: &[(&str, &str, &str)] = &[
// Labels distinct from the Combine grid's Expand and Collapse, which can show beside them.
("tools.expand", "Expand all tools", "maximize-2"),
("tools.collapse", "Collapse all tools", "minimize-2"),
("tools.all", "All tools", "layout-grid"),
("tools.all", "Back to all tools", "layout-grid"),
// The rail's button names the side it moves the rail to.
("view.rail.left", "Dock navigation rail on Left", "panel-left"),
("view.rail.right", "Dock navigation rail on Right", "panel-right"),
@@ -175,6 +175,7 @@ fn enabled(app: &PdfCraftApp, ctx: &egui::Context, command: &CommandRef) -> bool
let edit_objects = app.quick_tool == QuickTool::EditText && !organize;
let doc = app.active_ids().and_then(|(_, id)| app.session.get(id));
text || match command.id.as_str() {
QUIT => true,
NO_RECENT => false,
"file.open_recent" => index.is_none_or(|i| i < app.recent.len()),
"file.clear_recent" => !app.recent.is_empty(),
@@ -183,6 +184,9 @@ fn enabled(app: &PdfCraftApp, ctx: &egui::Context, command: &CommandRef) -> bool
"file.close" if !has_doc && super::mac_shortcuts(ctx) && !cfg!(target_arch = "wasm32") => true,
"edit.copy" if organize => enabled_id("page.copy"),
"edit.copy" if view.is_some_and(|v| v.session.picked_image.is_some()) => doc.is_some_and(|d| d.allows_copying()),
"edit.copy" | CUT if edit_objects && view.is_some_and(|v| v.session.image_selection.is_some()) => {
doc.is_some_and(|d| d.allows_copying() && (command.id != CUT || d.allows_modification()))
}
"edit.copy" | CUT if edit_objects && view.is_some_and(|v| v.session.objects.count() > 0) => {
doc.is_some_and(|d| d.allows_copying() && (command.id != CUT || d.allows_modification()))
}
@@ -121,7 +121,8 @@ fn params(count: usize, current: usize, unit: Unit) -> Vec<Param> {
}
out.response
})
.companions(MARKS),
.companions(MARKS)
.full_width(),
];
rows.extend(marks.map(|(key, label)| Param::new(key, label, ParamKind::bool(true))));
rows.push(Param::number("line_weight", tl!("Line weight"), 0.25, 0.25, 2).bounds(Some(0.1), Some(4.0)).unit(unit_kind(Unit::Points)));
+2 -1
View File
@@ -1377,7 +1377,8 @@ fn step_typing(
let mut now = crate::edit_text_ui::Typed::of(std::mem::take(text), selection.take(), std::mem::take(aligns));
let stepped = history.step(&mut now, step);
*text = now.text;
*selection = now.selection;
// A restored byte range belonged to the old text; the editor will place a fresh caret.
*selection = if stepped { None } else { now.selection };
*aligns = now.aligns;
stepped
}
+7 -5
View File
@@ -333,15 +333,17 @@ impl PdfCraftApp {
/// The guard is done. A finished quit closes the window, which asks `close_requested` again
/// and finds nothing left at risk; a quit that ended cancelled or held is called off.
fn end_close_guard(&mut self, ctx: &egui::Context, finished: bool) {
// Keep the completed quit until the window closes: settings still need the session saved
// before the guard closed its documents.
if finished && self.close_guard.as_ref().is_some_and(|guard| guard.scope() == CloseScope::Quit) {
close_root_window(ctx);
return;
}
let Some(guard) = self.close_guard.take() else { return };
if guard.scope() != CloseScope::Quit {
return;
}
if finished {
close_root_window(ctx);
} else {
self.session_keeper.quit_cancelled();
}
self.session_keeper.quit_cancelled();
}
/// Whether leaving would lose work: a document with unsaved changes, or an OCR review not yet
+4
View File
@@ -27,6 +27,7 @@ pub(crate) const CUT: &str = "edit.cut";
pub(crate) const PASTE: &str = "edit.paste";
pub(crate) const DELETE: &str = "edit.delete";
pub(crate) const SELECT_ALL: &str = "edit.select_all";
pub(crate) const QUIT: &str = "app.quit";
pub(crate) const NO_RECENT: &str = "file.no_recent";
/// An open document in the Window menu, `{"index": n}` in the tab strip.
pub(crate) const DOCUMENT: &str = "window.document";
@@ -44,6 +45,7 @@ const ROTATE_CCW: &str = "view.rotate.ccw";
/// The menu-only items: id, English label and the shortcut shown (the keys stay with the view). The
/// zoom and rotate ids are registry commands; only Fit to height has no registry row.
pub(crate) const EXTRA: &[(&str, &str, Option<Shortcut>)] = &[
(QUIT, "Quit", Some(Shortcut::cmd("Q"))),
(CUT, "Cut", Some(Shortcut::cmd("X"))),
(PASTE, "Paste", Some(Shortcut::cmd("V"))),
(DELETE, "Delete", Some(Shortcut { command: false, shift: false, mac_ctrl: false, key: "Delete" })),
@@ -116,6 +118,7 @@ const FILE: &[&str] = &[
"file.word_count",
SEP,
"print.dialog",
QUIT,
];
const CREATE: &[&str] = &["create.file", "create.multiple", "create.multiple_separate", "create.images", "create.clipboard"];
const EXPORT: &[&str] = &["export.docx", "export.pptx", "export.rtf", "export.html", "export.text", SEP, "export.image", "export.all_images"];
@@ -371,6 +374,7 @@ impl PdfCraftApp {
.documents(self.menu_documents());
bar.tag_item(&CommandRef::new("help.about"), ItemRole::About);
bar.tag_item(&CommandRef::new("app.preferences"), ItemRole::Settings);
bar.tag_item(&CommandRef::new(QUIT), ItemRole::Quit);
bar
}
+7
View File
@@ -4,6 +4,7 @@ use craft::behavior::GesturePhase;
use craft::keymap::CommandRef;
use craft::pages::ui::{PageThumbnails, ThumbnailEvent, moved_page};
use craft::ui::contract::{Props, Show, ShowContainer};
use craft::ui::display::Text;
use craft::ui::menu::{Menu, MenuItem, PanelRow};
use craft::ui::style::DataColor;
@@ -29,6 +30,11 @@ pub(super) fn body(app: &mut PdfCraftApp, ui: &mut egui::Ui) -> PanelResult {
let count = doc.info.pages.len();
let Some(view) = app.views.get_mut(index) else { return result };
if view.selected.items.len() > 1 {
let count = view.selected.items.len().to_string();
Text::new(crate::i18n::fmt(tl!("{n} pages selected"), &[("n", &count)])).show(ui);
}
let source = crate::canvas::pictures::DocPages::new(&app.session, id);
let before = view.thumbnail_zoom();
let mut zoom = f64::from(before);
@@ -36,6 +42,7 @@ pub(super) fn body(app: &mut PdfCraftApp, ui: &mut egui::Ui) -> PanelResult {
let grid_id = crate::canvas::organize::pages_panel_grid_id(view);
let output = PageThumbnails::new(tl!("Pages"), &source, &mut view.selected, current, DataColor::new(egui::Color32::WHITE))
.id(grid_id)
.picks_beside_current(true)
.editable(editable)
.size(&mut zoom)
.show(ui);
+4 -1
View File
@@ -11,7 +11,7 @@ use craft::behavior::dock::{
use craft::behavior::{Axis, DockSide, IconId};
use craft::keymap::CommandRef;
use craft::ui::buttons::IconButton;
use craft::ui::contract::{Bind, BodyCx, Show as _};
use craft::ui::contract::{Bind, BodyCx, Props as _, Show as _};
use craft::ui::docking::{DockConfig, DockPanels, GroupAt, HidePanels, IconicMode, PanelSpec};
use craft::ui::menu::PanelRow;
use craft::ui::patterns::dock::DockArea;
@@ -349,6 +349,9 @@ impl DockPanels<PanelId> for Panels<'_> {
PanelId::Tools => {
if self.app.left == LeftPanel::CalculationOrder {
crate::calc_order_ui::header(ui);
} else if crate::organize_panel::showing(self.app) {
IconButton::command(IconSpec::svg(IconId::new("chevron-left")), CommandRef::new("tools.all")).show(ui);
IconButton::command(IconSpec::svg(IconId::new("x")), CommandRef::new("page.organize")).label(tl!("Close panel")).show(ui);
} else if self.app.left == LeftPanel::AllTools {
IconButton::command(IconSpec::svg(IconId::new("maximize-2")), CommandRef::new("tools.expand")).show(ui);
}
@@ -261,6 +261,7 @@ fn skip_prompt(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
lines.push(crate::i18n::fmt(tl!("and {n} more"), &[("n", &more)]));
}
let out = Prompt::new(tl!("Leave out files that can't be read?"), tl!("These files can't be read, so they won't be in the combined PDF:"))
.opened(Bind::bound(&mut app.combine_tab.confirm_skip))
.lines(lines.into_iter().map(Into::into))
.answers([FooterButton::new(tl!("Combine the rest"), DialogRole::Accept), FooterButton::new(tl!("Cancel"), DialogRole::Cancel)])
.show(ui);
@@ -289,7 +290,8 @@ fn unlock_dialog(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
if let Some(error) = error {
dialog = dialog.error(error.into());
}
let out = dialog.show(ui);
let mut open = true;
let out = dialog.opened(Bind::bound(&mut open)).show(ui);
if let Some(mut answer) = out.answer {
let rows = answer.take_tag::<Vec<u64>>().unwrap_or(rows);
// It closes the dialog on success and sets the error on a wrong password.
+57 -41
View File
@@ -520,7 +520,8 @@ fn save_as_to_a_new_file_drops_earlier_revisions() {
h.run_steps(3);
queue_save(&out);
let ctx_h = h.ctx.clone();
assert!(h.state_mut().save_active(&ctx_h, pdfcraft_ui_egui::SaveTarget::As));
assert!(!h.state_mut().save_active(&ctx_h, pdfcraft_ui_egui::SaveTarget::As), "Save As awaits the picker");
h.run_steps(3);
let saved = saved_file(&out);
let count = |needle: &[u8]| saved.windows(needle.len()).filter(|w| *w == needle).count();
assert_eq!(count(b"%%EOF"), 1, "one revision only");
@@ -845,11 +846,14 @@ fn quitting_with_unsaved_changes_still_remembers_every_file() {
h.run_steps(3);
}
assert!(h.state().views.is_empty());
let mut app = crate::control::new_app();
app.apply_settings(&h.state().settings_snapshot());
app.reopen_last_files(&[]);
assert_eq!(open_paths(&app), files, "both files come back");
assert_eq!(app.active, Some(1), "with b.pdf in front, as when the quit began");
let settings = h.state().settings_snapshot();
let mut h = session_harness(move |app| {
app.apply_settings(&settings);
app.reopen_last_files(&[]);
});
support::wait_until(&mut h, "reopened files", |app| app.views.len() == 2);
assert_eq!(open_paths(h.state()), files, "both files come back");
assert_eq!(h.state().active, Some(1), "with b.pdf in front, as when the quit began");
}
#[test]
@@ -1295,7 +1299,9 @@ fn add_stops_at_the_256_custom_properties_the_tab_lists() {
type_into(&mut h, "Name:", "Other");
type_into(&mut h, "Value:", "x");
assert!(add_disabled(&h), "the draft holds 256");
h.get_by_label_contains("Client");
h.get_by_label("OK").click();
h.run_steps(3);
assert!(custom_properties(&h).contains(&("Client".to_string(), "Acme".to_string())));
// 257 in the file: after a Delete a new name would still be past the 256 listed.
let mut h = with_props(257);
@@ -1482,7 +1488,7 @@ fn combine_files_opens_in_its_own_tab() {
h.execute("page.combine");
h.run_steps(3);
assert!(h.state().combine_showing() && h.state().active.is_none());
h.get_by_label("Add the files to combine");
h.get_by_label_contains("Add the files to combine");
// Back to the document, then to Combine through its tab.
h.get_by_label("doc.pdf").click();
h.run_steps(3);
@@ -1752,6 +1758,7 @@ fn a_folder_adds_its_pdfs_images_and_text_in_order_and_optionally_its_subfolders
h.run_steps(4);
assert_eq!(combine_names(&h), ["notes.txt", "page2.PDF", "page10.pdf"], "numbers by value");
// The toolbar's menu: the folder and its subfolders, as one undo step.
queue_pick(&[dir.as_path()]);
h.get_by_label("More ways to add files").click();
h.run_steps(2);
h.get_by_label("Add folder and subfolders…").click();
@@ -1811,8 +1818,8 @@ fn files_that_cannot_be_read_are_listed_and_left_out_once_the_user_agrees() {
h.get_by_role_and_label(Role::Button, "Combine").click();
h.run_steps(3);
h.get_by_role_and_label(Role::Dialog, "Leave out files that can't be read?");
h.get_by_label("• broken.jpg");
h.get_by_label("• archive.zip");
h.get_by_label_contains("• broken.jpg");
h.get_by_label_contains("• archive.zip");
h.get_by_label("Cancel").click();
h.run_steps(3);
assert!(h.query_all_by_label("Leave out files that can't be read?").next().is_none());
@@ -2075,12 +2082,14 @@ fn plus_between_pages_inserts_picked_files_there_in_order() {
queue_pick(&[note.as_path()]);
h.get_by_label("Insert a file before page 1").click();
h.run_steps(4);
queue_pick(&[note.as_path()]);
h.get_by_label("Insert a file at the end").click();
h.run_steps(4);
assert_eq!(texts_of(h.state(), 0), ["a note", "Page 1", "Page 2", "Page 3", "a note"]);
// The toolbar button still inserts after the selection, not at the last "+" used.
h.get_by_label("Page 2").click();
h.run_steps(2);
queue_pick(&[note.as_path()]);
insert_menu(&mut h, "Insert pages from a file…");
h.run_steps(4);
assert_eq!(texts_of(h.state(), 0), ["a note", "Page 1", "a note", "Page 2", "Page 3", "a note"]);
@@ -2183,6 +2192,8 @@ fn files_dropped_on_the_pages_panel_are_inserted_there() {
let thumb = panel_thumb_rect(&h, "Page 2");
h.hover_at(thumb.center() - egui::vec2(0.0, thumb.height() * 0.25));
h.run_steps(2);
h.input_mut().hovered_files = vec![egui::HoveredFile { path: Some("extra.pdf".into()), mime: String::new() }];
h.step();
assert_eq!(h.state().views[0].panel_gap, Some(1));
drop_files(&mut h, vec![Dropped("extra.pdf", fixture(2)), Dropped("note.txt", b"a note".to_vec())]);
h.run_steps(4);
@@ -2424,17 +2435,18 @@ fn launch_display_override_survives_password_retry_without_changing_defaults() {
let mut file = std::fs::OpenOptions::new().write(true).create_new(true).open(&path).unwrap();
file.write_all(&protected("reader", "owner", -4)).unwrap();
drop(file);
let mut app = crate::control::new_app();
app.set_option(&egui::Context::default(), "default-layout", "continuous").unwrap();
app.open_path_with_display(path.to_str().unwrap(), PageLayout::TwoUp, false);
assert!(app.views.is_empty() && app.password_prompt.is_some());
app.submit_password(&egui::Context::default(), Some("wrong".into()));
assert!(app.views.is_empty() && app.password_prompt.is_some());
app.submit_password(&egui::Context::default(), Some("reader".into()));
assert_eq!(app.views.len(), 1);
assert_eq!(app.views[0].view.display, PageLayout::TwoUp);
assert!(!app.views[0].continuous());
assert_eq!(app.settings_snapshot().layout.default_layout.as_deref(), Some("continuous"));
let mut h = session_harness(|app| app.set_option(&egui::Context::default(), "default-layout", "continuous").unwrap());
h.state_mut().open_path_with_display(path.to_str().unwrap(), PageLayout::TwoUp, false);
support::wait_until(&mut h, "password prompt", |app| app.password_prompt.is_some());
assert!(h.state().views.is_empty());
h.state_mut().submit_password(&egui::Context::default(), Some("wrong".into()));
support::wait_until(&mut h, "wrong password", |app| app.password_prompt.as_ref().is_some_and(|p| p.error.is_some()));
assert!(h.state().views.is_empty());
h.state_mut().submit_password(&egui::Context::default(), Some("reader".into()));
support::wait_until(&mut h, "unlocked document", |app| app.views.len() == 1);
assert_eq!(h.state().views[0].view.display, PageLayout::TwoUp);
assert!(!h.state().views[0].continuous());
assert_eq!(h.state().settings_snapshot().layout.default_layout.as_deref(), Some("continuous"));
std::fs::remove_file(path).unwrap();
}
@@ -2956,14 +2968,13 @@ fn copying_out_of_a_document_honours_its_security() {
app.set_option(&egui::Context::default(), "language", "en").unwrap();
app.open_bytes(&egui::Context::default(), "no-copy.pdf", None, protected("pw", "owner", -1 ^ 0b1_0000)).unwrap();
app.submit_password(&cc.egui_ctx, Some(password.into()));
// One page at a time: Select All takes that page's text (scrolling continuously it would
// take both pages', #2639; what is tested here is the security of copying it).
if let Some(v) = app.views.first_mut() {
v.view.continuous = false;
}
app
}
});
support::wait_until(&mut h, "unlocked document", |app| !app.views.is_empty());
// One page at a time: Select All takes that page's text (scrolling continuously it would
// take both pages', #2639; what is tested here is the security of copying it).
h.state_mut().views[0].view.continuous = false;
// Select the page's text once its text layer is loaded (up to ~4 s: a loaded test machine
// can take far longer than the 0.2 s this used to allow).
for _ in 0..200 {
@@ -5160,9 +5171,13 @@ fn typed_small_coloured_text_size_survives_save_and_reopen() {
h.event(egui::Event::Text("6.5".into()));
h.key_press(Key::Enter);
h.run_steps(4);
h.get_by_label("Colour").click();
h.get_by_label("Text color").click();
h.run_steps(2);
h.get_by_label("Blue").click();
h.get_by_role_and_label(Role::SpinButton, "Blue").click();
h.key_press_modifiers(Modifiers::COMMAND, Key::A);
h.event(egui::Event::Text("255".into()));
h.run_steps(2);
h.get_by_role_and_label(Role::Button, "OK").click();
h.run_steps(4);
let id = h.state().views[0].id;
let lines = h.state().session.get(id).unwrap().text_lines(0);
@@ -6101,7 +6116,9 @@ fn pages_panel(pages: usize) -> Harness<'static, PdfCraftApp> {
}
fn picked(h: &Harness<'static, PdfCraftApp>) -> Vec<usize> {
h.state().views[0].selected.items.iter().copied().collect()
let mut pages = h.state().views[0].selected.items.clone();
pages.sort_unstable();
pages
}
#[test]
@@ -8422,7 +8439,7 @@ fn page_properties_sets_the_tab_order_of_the_selected_pages() {
let mut h = organize(3);
h.get_by_label("Page 1").click();
h.run_steps(2);
h.get_by_label("Page 3").click();
h.get_by_label("Page 3").click_modifiers(Modifiers::COMMAND);
h.run_steps(2);
h.get_by_label("Page properties").click();
h.run_steps(3);
@@ -9372,13 +9389,12 @@ fn crop_action_pills_interactive_and_apply_cancel_reset() {
set_crop_box(&mut h, smaller);
h.run_steps(2);
let pill_y = smaller.max.y + 17.0;
let done_pos = egui::pos2(smaller.max.x - 20.0, pill_y);
let done_pos = h.get_by_role_and_label(Role::Button, "Done").rect().center();
h.hover_at(done_pos);
h.run_steps(1);
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::PointingHand, "Done pill has PointingHand cursor");
let cancel_pos = egui::pos2(smaller.max.x - 85.0, pill_y);
let cancel_pos = h.get_by_role_and_label(Role::Button, "Cancel").rect().center();
h.hover_at(cancel_pos);
h.run_steps(1);
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::PointingHand, "Cancel pill has PointingHand cursor");
@@ -9395,7 +9411,7 @@ fn crop_action_pills_interactive_and_apply_cancel_reset() {
h.run_steps(2);
// Click "Remove Crop" pill
let reset_pos = egui::pos2(smaller.max.x - 170.0, pill_y);
let reset_pos = h.get_by_role_and_label(Role::Button, "Remove Crop").rect().center();
h.hover_at(reset_pos);
h.run_steps(1);
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::PointingHand, "Remove Crop pill has PointingHand cursor");
@@ -9407,7 +9423,7 @@ fn crop_action_pills_interactive_and_apply_cancel_reset() {
// Re-set smaller crop and click "Done" pill to apply
set_crop_box(&mut h, smaller);
h.run_steps(2);
let done_pos_after = egui::pos2(smaller.max.x - 20.0, pill_y);
let done_pos_after = h.get_by_role_and_label(Role::Button, "Done").rect().center();
click_at(&mut h, done_pos_after);
h.run_steps(4);
@@ -10001,7 +10017,7 @@ fn shown_on_its_page_only(h: &mut Harness<'static, PdfCraftApp>, plain: &image::
/// Where a mode bar tab is, by its label.
fn mode_tab(h: &Harness<'static, PdfCraftApp>, label: &str) -> egui::Rect {
h.get_all_by_role_and_label(Role::Button, label).map(|n| n.rect()).find(|r| r.bottom() < 120.0).expect("a mode tab")
h.get_all_by_role_and_label(Role::Tab, label).map(|n| n.rect()).find(|r| r.bottom() < 120.0).expect("a mode tab")
}
/// The cursor over each mode bar tab that page 1's text lies under, once that text is scrolled
@@ -10312,10 +10328,10 @@ fn format_panel_shows_selection_size_and_updates_after_font_applied() {
h.run_steps(1);
}
use egui::accesskit::Role;
let size_node = h.get_by_role_and_label(Role::TextInput, "Font size");
let size_node = h.get_by_role_and_label(Role::SpinButton, "Font size");
assert_eq!(size_node.value().as_deref(), Some("12"), "size text input value is 12");
let font_node = h.get_by_role_and_label(Role::ComboBox, "Font");
let font_node = h.get_by_role_and_label(Role::ComboBox, "Font family");
assert_eq!(font_node.value().as_deref(), Some("Helvetica"), "initial font is Helvetica");
// Apply Times to the selection
@@ -10325,7 +10341,7 @@ fn format_panel_shows_selection_size_and_updates_after_font_applied() {
h.run_steps(4);
// Font combo box for the whole block is now Mixed because Heading is Helvetica and Paragraph is Times
let font_node = h.get_by_role_and_label(Role::ComboBox, "Font");
let font_node = h.get_by_role_and_label(Role::ComboBox, "Font family");
assert_eq!(font_node.value().as_deref(), Some("Mixed"), "whole block has mixed fonts");
// Apply Times to the whole block
@@ -10335,7 +10351,7 @@ fn format_panel_shows_selection_size_and_updates_after_font_applied() {
h.run_steps(4);
// Now all text is Times, so font combo box updates to Times
let font_node = h.get_by_role_and_label(Role::ComboBox, "Font");
let font_node = h.get_by_role_and_label(Role::ComboBox, "Font family");
assert_eq!(font_node.value().as_deref(), Some("Times"), "font combo box updates to Times");
}
@@ -10451,7 +10467,7 @@ fn whole_paragraph_alignment_stays_available_without_a_row_selection() {
h.key_press(Key::End);
h.run_steps(2);
assert!(!h.get_by_label("Alignment").accesskit_node().is_disabled());
align_by_pointer(&mut h, "Align right");
align_by_pointer(&mut h, "Right align text");
assert!(h.state().views[0].session.line_editor.is_some());
h.key_press_modifiers(Modifiers::COMMAND, Key::Z);
h.run_steps(3);