mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 04:58:07 +00:00
Merge branch 'red7/g6' into area/app-1
This commit is contained in:
@@ -1605,6 +1605,11 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu
|
||||
if out.toggle_white_space {
|
||||
view.view.hide_white_space = !view.view.hide_white_space;
|
||||
}
|
||||
// The reader's own scroll (the wheel, a scroll bar, the view's keys) ends following the search; a flash's go-to is
|
||||
// not theirs.
|
||||
if out.scrolled {
|
||||
view.end_find_following();
|
||||
}
|
||||
// Full screen shows the page alone, so its keys are the page's: with nothing else holding the keyboard, the page
|
||||
// view takes it, and the presenter's keys reach the running tool.
|
||||
if presenting && ui.ctx().memory(|m| m.focused()).is_none() {
|
||||
|
||||
@@ -450,14 +450,13 @@ impl PdfCraftApp {
|
||||
}
|
||||
"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);
|
||||
match id {
|
||||
"view.first_page" => v.go_to_page(0),
|
||||
"view.last_page" => v.go_to_end(),
|
||||
// A step turns a whole spread in two-page view.
|
||||
"view.next_page" => v.step_page(true),
|
||||
_ => v.step_page(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
"view.layout.single" | "view.layout.two_up" => {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use craft::keymap::{Key, Mods};
|
||||
use craft::menu::Chord;
|
||||
use craft::ui::runtime::commands::{
|
||||
AppCatalog, Binding, CommandDef, CommandDefError, CommandGate, CommandInput, CommandKind, CommandRef, CommandState, Scope,
|
||||
};
|
||||
@@ -58,7 +60,7 @@ fn kind_of(id: &str) -> CommandKind {
|
||||
pub(crate) fn catalog(mac: bool) -> Result<AppCatalog, CommandDefError> {
|
||||
let mut defs: Vec<CommandDef> = Vec::new();
|
||||
let mut seen: std::collections::HashSet<String> = std::collections::HashSet::new();
|
||||
let mut push = |def: CommandDef, shortcut: Option<craft::menu::Chord>| {
|
||||
let mut push = |def: CommandDef, chords: Vec<Chord>| {
|
||||
if !seen.insert(def.command.id.clone()) {
|
||||
return;
|
||||
}
|
||||
@@ -68,28 +70,41 @@ pub(crate) fn catalog(mac: bool) -> Result<AppCatalog, CommandDefError> {
|
||||
} else {
|
||||
def
|
||||
};
|
||||
defs.push(match shortcut {
|
||||
Some(chord) => def.with_default(Binding::new(chord)),
|
||||
None => def,
|
||||
});
|
||||
defs.push(chords.into_iter().fold(def, |def, chord| def.with_default(Binding::new(chord))));
|
||||
};
|
||||
for spec in engine::COMMANDS.iter().filter(|s| !FRAMEWORK_EDIT.contains(&s.id)) {
|
||||
let mut def = CommandDef::new(CommandRef::new(spec.id), spec.label, Scope::app());
|
||||
if !spec.icon.is_empty() {
|
||||
def = def.with_icon(spec.icon);
|
||||
}
|
||||
push(def, spec.shortcut_for(mac).and_then(menus::chord));
|
||||
let mut chords: Vec<Chord> = spec.shortcut_for(mac).and_then(menus::chord).into_iter().collect();
|
||||
chords.extend(second_chords(spec.id));
|
||||
push(def, chords);
|
||||
}
|
||||
for (id, label, shortcut) in EXTRA.iter().filter(|(id, ..)| !FRAMEWORK_EDIT.contains(id)) {
|
||||
push(CommandDef::new(CommandRef::new(*id), *label, Scope::app()), shortcut.and_then(menus::chord));
|
||||
push(CommandDef::new(CommandRef::new(*id), *label, Scope::app()), shortcut.and_then(menus::chord).into_iter().collect());
|
||||
}
|
||||
for (id, label, icon) in CATALOG_ONLY {
|
||||
push(CommandDef::new(CommandRef::new(*id), *label, Scope::app()).with_icon(*icon), None);
|
||||
push(CommandDef::new(CommandRef::new(*id), *label, Scope::app()).with_icon(*icon), Vec::new());
|
||||
}
|
||||
// The rows are static, so the catalog never changes generation.
|
||||
AppCatalog::new(defs, 0)
|
||||
}
|
||||
|
||||
/// 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.
|
||||
fn second_chords(id: &str) -> Vec<Chord> {
|
||||
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<AppCatalog> {
|
||||
let cell = if mac { &CATALOG_MAC } else { &CATALOG_WIN };
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use craft::host::queue::{JobQueue, Priority, QueueOptions};
|
||||
use craft::host::queue::{JobQueue, Priority, QueueOptions, QueueOrder};
|
||||
use craft::host::{Jobs, Wake};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use craft::print::ui::HostedPrint;
|
||||
@@ -142,7 +142,8 @@ impl PrintTasks {
|
||||
two_sided: JobQueue::new(
|
||||
jobs.clone(),
|
||||
wake.clone(),
|
||||
QueueOptions { lanes: TWO_SIDED_READS, name: "print-two-sided", ..QueueOptions::default() },
|
||||
// A read for each pick, in the order the picks came.
|
||||
QueueOptions { lanes: TWO_SIDED_READS, name: "print-two-sided", order: QueueOrder::OldestFirst },
|
||||
),
|
||||
jobs: JobQueue::new(jobs, wake.clone(), options("print-jobs")),
|
||||
running: Vec::new(),
|
||||
@@ -410,6 +411,7 @@ impl PdfCraftApp {
|
||||
if let Some(p) = d.printer.clone() {
|
||||
self.read_papers_in_background(p);
|
||||
}
|
||||
self.show_chosen_printer();
|
||||
}
|
||||
|
||||
/// Pick up a printer list, driver options or a spooled job that finished (each frame).
|
||||
@@ -499,10 +501,12 @@ impl PdfCraftApp {
|
||||
let Some(source) = self.two_sided_source.clone() else { return };
|
||||
let Some(name) = self.print_draft.printer.clone() else { return };
|
||||
let queue = &self.print_tasks.two_sided;
|
||||
// A read is out from its submit until its answer arrives, whether or not its lane has started it yet.
|
||||
let out = queue.counts();
|
||||
if !self.print_tasks.listed.iter().any(|p| p.name == name)
|
||||
|| self.print_draft.two_sided.contains_key(&name)
|
||||
|| queue.contains(&name)
|
||||
|| queue.counts().running >= TWO_SIDED_READS
|
||||
|| out.queued + out.running >= TWO_SIDED_READS
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -308,6 +308,19 @@ impl PdfCraftApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows the printer the app chose outside the dialog (a fresh list's default, the one printed to last) and the
|
||||
/// two-sided choice its setup brought back in the open dialog, whose settings the next pass reads into the draft:
|
||||
/// the dialog's own fallback for a printer the list doesn't have would otherwise win.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(super) fn show_chosen_printer(&mut self) {
|
||||
let Some(printer) = self.print_draft.printer.clone() else { return };
|
||||
let duplex = duplex_to_ui(self.print_draft.duplex);
|
||||
let Some(dialog) = self.dialogs.get_mut::<HostedPrint>() else { return };
|
||||
let settings = &mut dialog.state_mut().settings;
|
||||
settings.destination = Destination::Printer(printer);
|
||||
settings.duplex = duplex;
|
||||
}
|
||||
|
||||
fn answer_print(&mut self, answer: Result<(), Label>) {
|
||||
if let Some(dialog) = self.dialogs.get_mut::<HostedPrint>() {
|
||||
dialog.answer_ok(answer);
|
||||
|
||||
@@ -82,7 +82,7 @@ fn checking_fixing_skipping_and_reporting() {
|
||||
assert!(h.execute("a11y.check"));
|
||||
h.run_steps(2);
|
||||
h.get_by_role_and_label(Role::Dialog, "Accessibility Checker Options");
|
||||
h.get_by_label_contains("31 of 32");
|
||||
assert!(h.query_all_by_label_contains("31 of 32").next().is_some(), "the options say how many checks run");
|
||||
h.get_by_label("Document title is showing in title bar");
|
||||
h.get_by_label("Start Checking").click();
|
||||
h.run_steps(3);
|
||||
|
||||
@@ -170,8 +170,8 @@ fn the_pdf_optimizer_dialog_saves_an_optimized_copy() {
|
||||
assert!(h.execute("optimize.advanced"));
|
||||
h.run_steps(2);
|
||||
h.get_by_role_and_label(Role::Dialog, "PDF Optimizer");
|
||||
h.get_by_label("Color Images");
|
||||
h.get_by_label("Monochrome Images");
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Heading, "Color Images");
|
||||
h.get_by_role_and_label(Role::Heading, "Monochrome Images");
|
||||
// Monochrome Images ▸ Downsample to can be turned off.
|
||||
h.get_by_label("Downsample to").click();
|
||||
h.run_steps(2);
|
||||
|
||||
@@ -227,7 +227,7 @@ fn document_scripts_and_preferences() {
|
||||
}
|
||||
other => panic!("the Document JavaScripts dialog is not open: {other:?}"),
|
||||
}
|
||||
h.get_by_label("Save").click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Document JavaScripts").get_by_label("Save").click();
|
||||
h.run_steps(2);
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
assert_eq!(h.state().session.get(id).unwrap().document_scripts()[0].0, "init");
|
||||
|
||||
@@ -94,6 +94,14 @@ pub(crate) fn harness_with_settings(settings: Option<String>) -> Rig {
|
||||
harness_saving(settings, 1)
|
||||
}
|
||||
|
||||
/// The app started again on the preferences `saved` left, as the settings store hands them back, with the form open.
|
||||
fn harness_restarted(saved: pdfcraft_ui_egui::settings::PdfCraftSettings) -> Rig {
|
||||
rig_on(saves(1), move |app| {
|
||||
app.apply_settings(&saved);
|
||||
app.open_bytes(&egui::Context::default(), "form.pdf", None, include_bytes!("../data/form.pdf").to_vec()).unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
fn harness_saving(settings: Option<String>, saves_count: usize) -> Rig {
|
||||
rig_on(saves(saves_count), move |app| {
|
||||
if let Some(json) = &settings {
|
||||
@@ -236,6 +244,12 @@ impl Rig {
|
||||
self.listed()["notes"].as_array().is_some_and(|notes| notes.iter().any(|n| n == key))
|
||||
}
|
||||
|
||||
/// Whether the preview shows why the draft can't print a document of `pages` pages, as the draft gives the reason.
|
||||
fn preview_says_why(&self, pages: usize) -> bool {
|
||||
let why = self.state().print_draft.settings(pages, &[]).err().expect("the draft can't print");
|
||||
self.query_by_label_contains(&why).is_some()
|
||||
}
|
||||
|
||||
/// Adds a custom paper through the custom row, as automation does: its fields, then its Add.
|
||||
pub(crate) fn add_custom(&mut self, name: &str, width: f64, length: f64) {
|
||||
self.set("custom_name", json!(name));
|
||||
@@ -381,7 +395,7 @@ fn invalid_ranges_are_explained_in_the_preview() {
|
||||
h.set("which", json!("range"));
|
||||
h.set("range", json!("7"));
|
||||
assert!(h.state().print_draft.settings(1, &[]).is_err(), "page 7 of a one-page document is out of range");
|
||||
assert!(h.has_note("note.range"), "the preview says why"); // PLAN: assumed key
|
||||
assert!(h.preview_says_why(1), "the preview says why");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -402,12 +416,12 @@ fn cut_stack_dialog_previews_saves_and_refuses_duplex() {
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.pager(), (1, 3));
|
||||
assert!(h.has_note("note.cut_stack"));
|
||||
h.get_by_label("›").click();
|
||||
h.get_by_role_and_label(Role::Button, "Next").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.pager(), (2, 3));
|
||||
h.set("duplex", json!("long_edge"));
|
||||
assert_eq!(h.state().print_draft.duplex, Some(Duplex::LongEdge));
|
||||
assert!(h.has_note("note.duplex"));
|
||||
assert!(h.preview_says_why(10), "cut and stack needs one-sided sheets");
|
||||
let ctx_h = h.ctx.clone();
|
||||
assert!(h.state_mut().print_now(&ctx_h).is_err());
|
||||
h.set("duplex", json!("off"));
|
||||
@@ -547,8 +561,8 @@ fn print_dialog_shows_the_printer_driver_options() {
|
||||
d.show_driver_options = true;
|
||||
}
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Printer properties");
|
||||
h.get_by_label("Media");
|
||||
assert!(h.query_all_by_label("Printer properties").next().is_some(), "the driver's own section shows");
|
||||
h.get_by_role_and_label(Role::Heading, "Media");
|
||||
h.get_by_label("Paper tray");
|
||||
// The selected sheet's media is always sent, independently of changed driver properties.
|
||||
let media = vec![("media".to_string(), "Letter".to_string())];
|
||||
@@ -626,7 +640,7 @@ fn custom_page_cannot_silently_match_a_standard_paper() {
|
||||
}
|
||||
|
||||
/// The key of the note that points a driver without two-sided settings to its Properties.
|
||||
const TWO_SIDED_NOTE: &str = "note.two_sided"; // PLAN: assumed key
|
||||
const TWO_SIDED_NOTE: &str = "note.duplex";
|
||||
|
||||
/// Windows' printer list doesn't say which drivers take two-sided settings: reading a printer
|
||||
/// Windows can't reach takes it about 48 s (#2192). The dialog lists every printer at once and
|
||||
@@ -892,7 +906,7 @@ fn printer_options_are_read_off_the_gui_thread_and_a_dead_read_offers_nothing()
|
||||
let ask = |h: &mut Rig, printer: &str| {
|
||||
h.pick(Some(printer));
|
||||
h.settle();
|
||||
h.get_by_label("Properties…").click();
|
||||
h.get_by_role_and_label(Role::Button, "Properties…").click();
|
||||
h.run_steps(1);
|
||||
};
|
||||
ask(&mut h, "Office");
|
||||
@@ -1392,8 +1406,7 @@ fn a_custom_paper_prints_at_its_size_and_its_printer_keeps_it() {
|
||||
assert_eq!(h.state().print_draft.setups.first().map(|(p, s)| (p.as_str(), s.paper.as_str())), Some(("Labeller", "Label 4×6")));
|
||||
|
||||
// After a restart the list has it, and the printer starts on it.
|
||||
let settings = saved_json(h.state());
|
||||
let mut h = harness_with_settings(Some(settings));
|
||||
let mut h = harness_restarted(h.state().settings_snapshot());
|
||||
list_printers(&mut h, &["Labeller"]);
|
||||
assert_eq!(h.state().print_draft.paper_count(), pdfcraft_engine::print::PAPERS.len() + 1);
|
||||
h.state_mut().print_draft.paper = 0;
|
||||
@@ -1436,7 +1449,7 @@ fn a_booklet_decides_two_sided_itself() {
|
||||
let d = &h.state().print_draft;
|
||||
assert_eq!(d.duplex, Some(Duplex::LongEdge), "the Two-sided choice is kept");
|
||||
assert_eq!(d.job("x").duplex, Some(Duplex::ShortEdge), "both sides flip on the short edge");
|
||||
assert!(h.query_all_by_label("Creep:").next().is_some(), "a Creep field beside Binding");
|
||||
assert!(h.query_all_by_label("Creep").next().is_some(), "a Creep field beside Binding");
|
||||
h.state_mut().print_draft.creep = 1.5;
|
||||
let layout = h.state().print_draft.settings(4, &[]).map(|s| s.layout);
|
||||
assert!(matches!(layout, Ok(pdfcraft_engine::print::Layout::Booklet { creep, .. }) if creep == 1.5), "the creep reaches the booklet (#6777)");
|
||||
@@ -1444,14 +1457,12 @@ fn a_booklet_decides_two_sided_itself() {
|
||||
h.state_mut().print_draft.booklet_subset = subset;
|
||||
assert_eq!(h.state().print_draft.job("x").duplex, Some(Duplex::Off), "{subset:?} is one pass of a manual duplex");
|
||||
}
|
||||
let keeps_its_own =
|
||||
"This printer's driver doesn't take two-sided settings from other programs, so its own setting applies. Change it in Properties…";
|
||||
assert!(h.query_by_label(keeps_its_own).is_none());
|
||||
assert!(!h.has_note(TWO_SIDED_NOTE));
|
||||
h.pick(Some("Inkjet"));
|
||||
h.state_mut().print_draft.booklet_subset = BookletSubset::BothSides;
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().print_draft.job("x").duplex, None, "the inkjet's own two-sided setting prints both sides");
|
||||
assert!(h.query_by_label(keeps_its_own).is_some(), "the dialog says so");
|
||||
assert!(h.has_note(TWO_SIDED_NOTE), "the dialog says so");
|
||||
h.state_mut().print_draft.booklet_subset = BookletSubset::FrontOnly;
|
||||
assert_eq!(h.state().print_draft.job("x").duplex, Some(Duplex::Off), "one side stays one-sided");
|
||||
h.pick(Some("Laser"));
|
||||
@@ -1698,8 +1709,8 @@ fn each_printer_keeps_what_it_last_printed_with_across_a_restart() {
|
||||
|
||||
// After a restart the label printer, printed to last, is chosen again with its setup, not
|
||||
// the system default; choosing the office printer brings back A4, Fit and two-sided.
|
||||
let saved = saved_json(h.state());
|
||||
let mut r = harness_with_settings(Some(saved.clone()));
|
||||
let saved = h.state().settings_snapshot();
|
||||
let mut r = harness_restarted(saved.clone());
|
||||
attach(&mut r);
|
||||
r.open();
|
||||
r.settle();
|
||||
@@ -1710,7 +1721,7 @@ fn each_printer_keeps_what_it_last_printed_with_across_a_restart() {
|
||||
|
||||
// A remembered printer that is gone falls back to the system default, with its own setup.
|
||||
*listed.lock().unwrap() = vec!["Office"];
|
||||
let mut gone = harness_with_settings(Some(saved));
|
||||
let mut gone = harness_restarted(saved);
|
||||
attach(&mut gone);
|
||||
gone.open();
|
||||
gone.settle();
|
||||
|
||||
@@ -82,18 +82,11 @@ fn marking_applying_and_clearing() {
|
||||
}
|
||||
h.drop_at(b);
|
||||
h.run_steps(4);
|
||||
eprintln!(
|
||||
"DIAG marking_applying_and_clearing: tool {:?} mode {:?} page {:?} from {a:?} to {b:?} cursor {:?}",
|
||||
h.state().quick_tool,
|
||||
h.state().mode,
|
||||
h.state().views[0].page_screen_rect(0),
|
||||
h.output().platform_output.cursor_icon
|
||||
);
|
||||
assert_eq!(marks(&h), 1);
|
||||
// Redact pages ▸ current page.
|
||||
h.execute("redact.pages");
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Mark Page Range");
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Mark Page Range");
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(marks(&h), 2);
|
||||
|
||||
@@ -141,7 +141,7 @@ fn create_signing_id(h: &mut Harness<'static, PdfCraftApp>) {
|
||||
h.get_by_label("Grace Hopper");
|
||||
h.get_by_label("Continue").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Sign as \"Grace Hopper\"");
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Heading, "Sign as \"Grace Hopper\"");
|
||||
}
|
||||
|
||||
fn sign_with_created_id(h: &mut Harness<'static, PdfCraftApp>, dir: &std::path::Path) {
|
||||
|
||||
@@ -344,11 +344,13 @@ fn find_one_match_per_page(h: &mut Harness<'static, PdfCraftApp>) -> usize {
|
||||
fn late_match_leaves_current(h: &mut Harness<'static, PdfCraftApp>, view: usize) -> bool {
|
||||
let f = h.state_mut().views[view].find.as_mut().expect("the find bar is open");
|
||||
let before = f.matches.current_match().cloned().expect("a current match");
|
||||
let mut ranges: Vec<std::ops::Range<usize>> = f.matches.matches().iter().filter(|m| m.page == before.page).map(|m| m.range.clone()).collect();
|
||||
// Ahead of the current match on its own page, or on the page before when it starts the page.
|
||||
let page = if before.range.start > 0 { before.page } else { before.page.checked_sub(1).expect("room for an earlier match") };
|
||||
let mut ranges: Vec<std::ops::Range<usize>> = f.matches.matches().iter().filter(|m| m.page == page).map(|m| m.range.clone()).collect();
|
||||
if !ranges.iter().any(|r| r.start == 0) {
|
||||
ranges.insert(0, 0..1);
|
||||
}
|
||||
f.matches.set_page(before.page, ranges);
|
||||
f.matches.set_page(page, ranges);
|
||||
f.matches.current_match() == Some(&before)
|
||||
}
|
||||
|
||||
@@ -509,7 +511,8 @@ fn marking_while_searching_does_not_jitter_or_reset_search_state() {
|
||||
assert_eq!(h.state().views[0].find.as_ref().unwrap().matches.len(), 15);
|
||||
|
||||
// If user is viewing page 3 and reruns find, the selected match must be on page 3 (index 9), not page 0
|
||||
h.state_mut().views[0].view.current = 3;
|
||||
h.state_mut().views[0].go_to_page(3);
|
||||
h.run_steps(2);
|
||||
h.state_mut().views[0].rerun_find();
|
||||
let current_p3 = h.state().views[0].find.as_ref().unwrap().matches.current();
|
||||
assert_eq!(current_p3, Some(9), "rerun_find must select the first match at or after the viewed page (page 3), but selected {:?}", current_p3);
|
||||
@@ -848,7 +851,7 @@ fn page_label_input_new_document_does_not_inherit_or_commit_the_previous_draft()
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().views[next].current(), 0, "unchanged Enter stays on the new document's first page");
|
||||
|
||||
h.get_by_label("a.pdf (edited)").click();
|
||||
tab(&h, "a.pdf").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().active, Some(0));
|
||||
assert_eq!((h.state().views[0].current(), h.state().views[0].page_input.as_str()), (3, "2"));
|
||||
@@ -882,7 +885,7 @@ fn page_label_input_preserves_typing_and_refreshes_after_navigation_and_tab_chan
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(3);
|
||||
assert_eq!((h.state().views[1].current(), h.state().views[1].page_input.as_str()), (1, "2"), "default labels still work");
|
||||
h.get_by_label("a.pdf (edited)").click();
|
||||
tab(&h, "a.pdf").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().views[0].page_input, "2", "returning to a document refreshes its idle label");
|
||||
|
||||
@@ -1328,7 +1331,14 @@ fn tab_and_window_show_the_document_title_when_asked() {
|
||||
h.run_steps(2);
|
||||
// The edits are unsaved, so the title says so (#3640).
|
||||
assert_eq!(h.state().window_title, "Quarterly report • — PdfCraft");
|
||||
h.get_by_label_contains("Quarterly report");
|
||||
tab(&h, "Quarterly report");
|
||||
}
|
||||
|
||||
/// The document tab named `name`, saved or modified (the tab bar adds the modified state to the name).
|
||||
fn tab<'h>(h: &'h Harness<'static, PdfCraftApp>, name: &str) -> egui_kittest::Node<'h> {
|
||||
let modified = format!("{name},");
|
||||
let name = name.to_owned();
|
||||
h.get_by(move |n| n.role() == egui::accesskit::Role::Tab && n.label().is_some_and(|l| l == name || l.starts_with(&modified)))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2037,18 +2047,8 @@ fn pages_panel_harness(sizes: &[(u32, u32)]) -> Harness<'static, PdfCraftApp> {
|
||||
h
|
||||
}
|
||||
|
||||
fn diag_page_nodes(h: &Harness<'static, PdfCraftApp>) {
|
||||
use egui_kittest::kittest::NodeT;
|
||||
let name = std::thread::current().name().unwrap_or("").rsplit("::").next().unwrap_or("").to_owned();
|
||||
for n in h.query_all_by_label_contains("Page") {
|
||||
let a = n.accesskit_node();
|
||||
eprintln!("DIAG {name}: {:?} {:?} {:?}", a.role(), a.label(), n.rect());
|
||||
}
|
||||
}
|
||||
|
||||
/// A thumbnail in the Pages panel (the panel lists pages as "Page n" buttons).
|
||||
fn thumbnail(h: &Harness<'static, PdfCraftApp>, label: &str) -> egui::Pos2 {
|
||||
diag_page_nodes(h);
|
||||
h.get_all_by_label(label).find(is_thumbnail).expect("the Pages panel thumbnail").rect().center()
|
||||
}
|
||||
|
||||
@@ -2098,7 +2098,6 @@ fn pages_panel_thumbnails_have_a_context_menu() {
|
||||
|
||||
/// Where the Pages panel draws page `n`'s thumbnail.
|
||||
fn thumbnail_rect(h: &Harness<'static, PdfCraftApp>, n: usize) -> egui::Rect {
|
||||
diag_page_nodes(h);
|
||||
h.get_all_by_label(&format!("Page {n}")).find(is_thumbnail).expect("the Pages panel thumbnail").rect()
|
||||
}
|
||||
|
||||
@@ -2585,12 +2584,6 @@ fn mouse_wheel_scrolls_while_selecting_text() {
|
||||
h.run_steps(1);
|
||||
h.hover_at(end);
|
||||
h.run_steps(2);
|
||||
eprintln!(
|
||||
"DIAG mouse_wheel_scrolls_while_selecting_text: page {page:?} start {start:?} glyph0 {:?} sel {:?} dragged {:?}",
|
||||
h.state().views[view].glyph_screen_pos(0, 0),
|
||||
h.state().views[view].selected_text(),
|
||||
h.ctx.dragged_id()
|
||||
);
|
||||
assert!(h.state().views[view].selected_text().is_some_and(|s| !s.is_empty()), "a text selection is active");
|
||||
assert!(h.ctx.dragged_id().is_some(), "the primary drag is still held");
|
||||
let before = h.state().views[view].page_screen_rect(0).unwrap().top();
|
||||
@@ -2624,12 +2617,6 @@ fn selection_wheel_harness() -> (Harness<'static, PdfCraftApp>, usize, egui::Pos
|
||||
h.run_steps(1);
|
||||
h.hover_at(end);
|
||||
h.run_steps(2);
|
||||
eprintln!(
|
||||
"DIAG selection_wheel_harness: page {page:?} start {start:?} glyph0 {:?} sel {:?} dragged {:?}",
|
||||
h.state().views[view].glyph_screen_pos(0, 0),
|
||||
h.state().views[view].selected_text(),
|
||||
h.ctx.dragged_id()
|
||||
);
|
||||
assert!(h.state().views[view].selected_text().is_some_and(|s| !s.is_empty()), "a text selection is active");
|
||||
assert!(h.ctx.dragged_id().is_some(), "the primary drag is still held");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user