App red round 6 g2: fixes from the g2 fixer

This commit is contained in:
Dylan M. Taylor
2026-11-19 09:58:21 -05:00
parent 072b69e0f8
commit 11caa7f82c
19 changed files with 108 additions and 35 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ impl AppServices {
update_source,
intake,
#[cfg(not(target_arch = "wasm32"))]
watch,
watch: reload::document_watch(watch),
}
}
+12 -6
View File
@@ -175,23 +175,29 @@ impl PdfCraftApp {
/// keeps comment tools from reopening it; opening it again lets them (#225). A choice made in
/// Read mode replaces the pane saved on the way in, so leaving Read mode doesn't undo it.
pub fn choose_right_panel(&mut self, panel: Option<RightPanel>) {
self.right_panel_chosen(self.right(), panel);
self.set_right(panel);
if let Some(panel) = panel {
self.last_right = panel;
}
}
/// What the user's choice of the right panel, from `before` to `panel`, is remembered as: here
/// or in the dock (its tabs and Close button).
pub(crate) fn right_panel_chosen(&mut self, before: Option<RightPanel>, panel: Option<RightPanel>) {
if self.mode == Mode::Read {
self.right_before_read = None;
}
if panel == Some(RightPanel::Comments) {
self.comments_panel_closed = false;
} else if panel.is_none() && self.right() == Some(RightPanel::Comments) {
} else if panel.is_none() && before == Some(RightPanel::Comments) {
self.comments_panel_closed = true;
}
if panel.is_some() {
self.right_panel_closed = false;
} else if self.right().is_some() {
} else if before.is_some() {
self.right_panel_closed = true;
}
self.set_right(panel);
if let Some(panel) = panel {
self.last_right = panel;
}
}
/// F4: closes the side panel, or reopens the one open last.
+6 -8
View File
@@ -10,7 +10,6 @@
use std::path::{Path, PathBuf};
use std::sync::Arc;
use craft::host::Wake;
use craft::platform::watch::{Changed, FileStamp, FileWatch, ReadPolicy};
use pdfcraft_engine::DocId;
@@ -20,12 +19,11 @@ use crate::PdfCraftApp;
/// still being written then costs one small read.
const TAIL: usize = 1024;
/// The watch of the open documents' files: a changed file is read whole once its last KiB holds
/// `%%EOF`. `wake` runs on the watch's worker when it finds a change; call `.inline()` on the
/// result for a watch that looks only when ticked (tests).
// PLAN: the app's `new(ctx)` and the tests' `AppServices` (pdf-hub-w1, L-183) build the watch they carry with this, so the read rule lives in one place
pub(crate) fn document_watch(wake: Wake) -> FileWatch<DocId> {
FileWatch::new(wake).read(ReadPolicy::Whole { tail: TAIL, complete: Arc::new(|end: &[u8]| end.windows(5).any(|w| w == b"%%EOF")) })
/// `watch` as the open documents' files are watched: a changed file is read whole once its last
/// KiB holds `%%EOF`. `AppServices::new` applies it to the watch it is given, the system's or a
/// test's, so the read rule lives in one place.
pub(crate) fn document_watch(watch: FileWatch<DocId>) -> FileWatch<DocId> {
watch.read(ReadPolicy::Whole { tail: TAIL, complete: Arc::new(|end: &[u8]| end.windows(5).any(|w| w == b"%%EOF")) })
}
impl PdfCraftApp {
@@ -221,7 +219,7 @@ mod tests {
let (intake, _) = craft::platform::open::FileIntake::new(Wake::none());
let clipboard = craft::platform::clipboard::Clipboard::new(craft::platform::clipboard::EventClipboard::new(|| 0, |_| Ok(0)));
// PLAN: assumed `AppServices::new(wake, clipboard, recovery_dir, update_source, intake, watch)` (L-207, pdf-hub-w1)
let services = crate::AppServices::new(Wake::none(), clipboard, None, None, intake, document_watch(Wake::none()).inline());
let services = crate::AppServices::new(Wake::none(), clipboard, None, None, intake, FileWatch::new(Wake::none()).inline());
let path = path.to_owned();
let h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |cc| {
crate::PdfCraftApp::install_runtime(&cc.egui_ctx);
+6
View File
@@ -1082,6 +1082,12 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession,
let mut tool = page_tool(cx.chosen, tool_cx, &mut *session, &mut bench, &mut fill, &pass.press);
let reply = ToolHost::new().momentary(momentary).run(ui, pass, &mut tool);
let mut finish = tool.finish();
// The comment gestures the run finished: each committed one is an engine edit, one undo step per drag.
let map = comments::PageMap::new(cx.info, body.pages, cx.rotation);
let now = ui.input(|i| i.time);
if let Some(edit) = comments::take_edits(&mut session.comments, &map, cx.info, cx.prefs, now) {
session.pending_edit = Some(edit);
}
finish.apply(fill, session, &tool_cx);
if let Some(why) = finish.refused.take() {
session.objects.notice = Some(why.into());
+1 -1
View File
@@ -311,7 +311,7 @@ pub(crate) fn page_tool<'a>(
let snap = caret_snap(tool, &cx, &session.texts, session.comments.tool.page);
let view = &mut session.comments;
let map = comments::PageMap::new(cx.info, cx.pages, cx.rotation);
let annotate = CommentsTool::new(&mut view.tool, &mut view.paste, map, &mut view.tool_done)
let annotate = CommentsTool::new(&mut view.tool, &mut view.paste, map, &mut view.tool_done, &mut view.tool_pressed)
.settings(tool, cx.comment_prefs, cx.allowed, cx.doc.comments_hidden())
.outcome(&mut session.pending_edit, &mut view.notice);
let annotate = match snap {
+7 -4
View File
@@ -313,11 +313,14 @@ impl PdfCraftApp {
"file.save_as" => {
self.save_active(ctx, SaveTarget::As);
}
"file.close" => {
if let Some(i) = active {
self.request_close_tab(ctx, i);
"file.close" => match active {
Some(i) => self.request_close_tab(ctx, i),
// macOS ⌘W closes the window when no document is open (#869), through the quit guard.
None if crate::commands::mac_shortcuts(ctx) && !cfg!(target_arch = "wasm32") => {
self.request_quit(ctx);
}
}
None => {}
},
"file.close_all" => self.close_all(ctx),
// PLAN: assumed the dialog openers are `PdfCraftApp` methods named as the sheet gives them (dialogs A-3..A-10), taking no argument unless the sheet names one.
"file.revert" => self.ask_revert(),
+1
View File
@@ -38,6 +38,7 @@ pub(crate) fn open_over<D: StackDialog>(app: &mut PdfCraftApp, dialog: D) -> Dia
fn windows(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
app.show_preferences(ui);
app.show_shortcuts(ui);
app.password_pass(ui);
crate::workflows::js_dialogs::show(app, ui);
crate::redact_ui::dialogs::show_props(app, ui);
crate::redact_ui::dialogs::show_search(app, ui);
+5
View File
@@ -444,10 +444,15 @@ pub fn dock(app: &mut PdfCraftApp, ui: &mut Ui) {
let output = DockArea::new("Dock", Bind::given(workspace), &mut panels, DockConfig::default().native_windows(false))
.hide(HidePanels::Except(&shown))
.show(ui);
let before = right_of(&app.dock);
for action in output.actions.into_iter().chain(output.requested) {
// The area drops what the workspace refuses; one refused here is stale, not the user's mistake.
drop(app.dock.apply(action, false, permissions));
}
let after = right_of(&app.dock);
if after != before {
app.right_panel_chosen(before, after);
}
if let Some(panel) = open_side(&app.dock).and_then(PanelId::side) {
app.last_right = panel;
}
+1 -1
View File
@@ -58,7 +58,7 @@ pub(crate) use state::PageCx;
use state::after_delete;
use state::login_name;
pub use state::{CommentView, Composer, ComposerKind};
pub(crate) use tool::{CommentsTool, PastePlacement, context_target, page_after_text, part_pressed};
pub(crate) use tool::{CommentsTool, PastePlacement, context_target, page_after_text, part_pressed, take_edits};
/// Maximum stroke thickness offered by commenting controls, in PDF points.
pub const MAX_LINE_WIDTH: f64 = 100.0;
@@ -164,6 +164,9 @@ pub struct CommentView {
pub context_at: Option<(usize, [f64; 2])>,
/// A one-shot tool just finished; the app returns to the Select tool unless pinned.
pub tool_done: bool,
/// The annotation tool took the open press (it did not answer `Ignored`): the drag, release and cancel are its,
/// not the text selection's.
pub(crate) tool_pressed: bool,
/// Snapshot of `(page, index)` comment slot identity from the last `DocInfo`, used to detect
/// when an edit removes or shifts `/Annots` entries under an active selection or editor.
pub(crate) slots: std::collections::HashMap<(usize, usize), CommentSlot>,
+39 -5
View File
@@ -45,6 +45,7 @@ pub(crate) struct CommentsTool<'a> {
notice: Option<&'a mut Option<&'static str>>,
map: PageMap<'a>,
done: &'a mut bool,
pressed: &'a mut bool,
quick: QuickTool,
prefs: Option<&'a CommentPrefs>,
allowed: bool,
@@ -54,8 +55,15 @@ pub(crate) struct CommentsTool<'a> {
impl<'a> CommentsTool<'a> {
/// The tool over `annotate` (kept in `CommentView::tool`, so a gesture lasts across passes), the paste slot, the
/// pages on screen and the flag Escape sets when it leaves the tool (`CommentView::tool_done`).
pub(crate) fn new(annotate: &'a mut AnnotateTool, paste: &'a mut Option<PastePlacement>, map: PageMap<'a>, done: &'a mut bool) -> Self {
/// pages on screen, the flag Escape sets when it leaves the tool (`CommentView::tool_done`) and whether the
/// annotation tool took the open press (`CommentView::tool_pressed`, kept across passes with the gesture).
pub(crate) fn new(
annotate: &'a mut AnnotateTool,
paste: &'a mut Option<PastePlacement>,
map: PageMap<'a>,
done: &'a mut bool,
pressed: &'a mut bool,
) -> Self {
CommentsTool {
annotate,
text: None,
@@ -64,6 +72,7 @@ impl<'a> CommentsTool<'a> {
notice: None,
map,
done,
pressed,
quick: QuickTool::Select,
prefs: None,
allowed: false,
@@ -103,9 +112,10 @@ impl<'a> CommentsTool<'a> {
self.map.page_at(Point::new(f64::from(at.x), f64::from(at.y)))
}
/// Whether the annotation tool holds a gesture: the drag, release and cancel are its, else the text's.
/// Whether the annotation tool holds the gesture, as it took the press or is clicking out a shape: the drag,
/// release and cancel are its, else the text's.
fn annotating(&self) -> bool {
self.annotate.in_flight().is_some() || !self.annotate.drawing().is_empty()
*self.pressed || !self.annotate.drawing().is_empty()
}
fn place(&mut self, page: usize, at: Pos2) {
@@ -204,6 +214,7 @@ impl CanvasTool for CommentsTool<'_> {
}
fn press(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) -> ToolAction {
*self.pressed = false;
if self.paste.is_some() {
// A click places the bundle, centred where it is clicked, on the page under it; a right-click lets it
// go. Nothing else on the page takes the press.
@@ -216,7 +227,28 @@ impl CanvasTool for CommentsTool<'_> {
}
return ToolAction::Done;
}
match self.annotate.press(pointer, cx) {
// A markup tool or Replace Text marks the text its drag selects (`page_after_text`): the text takes the press
// first. Under Select the comments come first, and a press no comment takes goes on to the text.
if matches!(self.quick, QuickTool::Comment(_))
&& let Some(text) = self.text.as_mut()
{
let action = text.press(pointer, cx);
if action != ToolAction::Ignored {
return action;
}
}
let action = self.annotate.press(pointer, cx);
*self.pressed = action != ToolAction::Ignored;
// A press on no comment passes through to the text (`EmptyPress::PassThrough`): it leaves the comments
// selected only while Shift or Cmd adds to the selection.
if action == ToolAction::Ignored
&& self.annotate.tool == AnnotationTool::Select
&& pointer.button == PointerButton::Primary
&& !(pointer.mods.shift || pointer.mods.cmd)
{
self.annotate.selected.clear();
}
match action {
ToolAction::Ignored => match self.text.as_mut() {
Some(text) => text.press(pointer, cx),
None => ToolAction::Ignored,
@@ -239,6 +271,7 @@ impl CanvasTool for CommentsTool<'_> {
} else if let Some(text) = self.text.as_mut() {
text.release(pointer, cx);
}
*self.pressed = false;
}
fn hover(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) {
@@ -254,6 +287,7 @@ impl CanvasTool for CommentsTool<'_> {
} else if let Some(text) = self.text.as_mut() {
text.cancel(reason, cx);
}
*self.pressed = false;
}
fn claims(&self) -> ToolClaims {
+2 -1
View File
@@ -46,7 +46,8 @@ fn run_and_create_actions() {
assert!(h.execute("actions.distribution"));
h.run_steps(2);
h.get_by_role_and_label(Role::Dialog, "Action Wizard");
h.get_by_label("1. Remove hidden information");
// The chosen action's description lists its numbered steps, one per line.
h.get_by_label_contains("1. Remove hidden information");
h.get_by_label("Start").click();
finish(&mut h, &jobs);
assert_eq!(support::shown_notice(&h).as_deref(), Some("Prepare for Distribution: 1 file done"));
+1 -1
View File
@@ -25,7 +25,7 @@ fn compare_two_versions() {
h.run_steps(4);
assert!(h.execute("doc.compare"));
h.run_steps(2);
h.get_by_label("Compare Files");
h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Compare Files");
h.get_by_label("Compare").click();
h.run_steps(3);
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Compare));
+1
View File
@@ -1382,6 +1382,7 @@ mod revert_tests {
// A document with no file asks where to save: the scripted answer arrives on a later pass.
h.state_mut().save_active(&ctx_h, pdfcraft_ui_egui::SaveTarget::InPlace);
crate::support::wait_until(&mut h, "the save", |s| s.views.first().and_then(|v| s.session.get(v.id)).is_some_and(|d| !d.dirty));
wait_for_file(&mut h, &path);
let saved = std::fs::read(&path).unwrap();
let ctx_h = h.ctx.clone();
assert!(h.state_mut().apply_edit(
+10 -1
View File
@@ -61,7 +61,16 @@ fn type_into(h: &mut H, label: &str, text: &str) {
fn cases() -> Vec<Case> {
vec![
Case { name: "default mode", page: "Documents and view", edit: |h| click(h, "E-Sign"), applied: |a| a.default_mode == Mode::Sign },
Case {
name: "default mode",
page: "Documents and view",
edit: |h| {
// A choice row is a drop-down: its options show once it opens.
click(h, "Default workspace mode");
click(h, "E-Sign");
},
applied: |a| a.default_mode == Mode::Sign,
},
Case {
name: "layout and continuous on the active view",
page: "Documents and view",
+2 -2
View File
@@ -293,12 +293,12 @@ fn encrypted(bytes: Vec<u8>, password: &str) -> Vec<u8> {
fn type_password(h: &mut Harness<'static, PdfCraftApp>, password: &str) {
// The prompt is laid out in the pass after the one that set it.
for _ in 0..10 {
if h.query_by_role(Role::PasswordInput).is_some() {
if h.query_by_role_and_label(Role::PasswordInput, "Password").is_some() {
break;
}
h.run_steps(1);
}
let field = h.get_by_role(Role::PasswordInput);
let field = h.get_by_role_and_label(Role::PasswordInput, "Password");
field.focus();
field.type_text(password);
h.run_steps(2);
+2 -2
View File
@@ -350,7 +350,7 @@ fn saving_over_a_file_changed_by_something_else_asks_first() {
let ctx_h = h.ctx.clone();
assert!(!h.state_mut().save_active(&ctx_h, SaveTarget::InPlace), "not written yet");
h.run_steps(2);
h.get_by_label("File changed");
h.get_by_role_and_label(egui::accesskit::Role::Dialog, "File changed");
h.get_by_label("Cancel").click();
h.run_steps(2);
assert_eq!(std::fs::read(&file.path).unwrap(), fixture(4), "Cancel keeps the newer file");
@@ -381,7 +381,7 @@ fn saving_checks_the_file_with_the_watcher_off_too() {
let ctx_h = h.ctx.clone();
assert!(!h.state_mut().save_active(&ctx_h, SaveTarget::InPlace));
h.run_steps(2);
h.get_by_label("File changed");
h.get_by_role_and_label(egui::accesskit::Role::Dialog, "File changed");
}
/// One file, one tab (#2166): opening a file that is open already brings its tab forward,
+5 -2
View File
@@ -6,7 +6,7 @@
use crate::support;
use crate::support::AppHarness as _;
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use egui_kittest::kittest::{NodeT, Queryable};
use pdfcraft_engine::SignatureStatus;
use pdfcraft_ui_egui::{PdfCraftApp, SignStep};
@@ -81,7 +81,10 @@ fn one_click_trust_stores_the_displayed_signer_not_the_embedded_root() {
};
// Open the signature row (a click picks it, Right opens a tree row) and use the one-click trust button.
h.get_by_label_contains("Signed by").click();
h.query_all_by(|n| n.role() == egui::accesskit::Role::TreeItem && n.label().is_some_and(|l| l.contains("Signed by")))
.next()
.expect("the signature's row")
.click();
h.run_steps(1);
h.key_press(egui::Key::ArrowRight);
h.run_steps(2);
+3
View File
@@ -68,6 +68,9 @@ fn checkbox_and_multiple_documents_do_not_edit_pdf_state() {
h.set_option("dialog", "preferences").unwrap();
h.run_steps(3);
assert_eq!(h.state().settings_snapshot().behavior.show_page_edge_shadows, Some(true));
// Preferences shows one page at a time; the shadows are on Appearance.
h.get_by_label("Appearance").click();
h.run_steps(3);
let checkbox = h.get_by_label("Show Page Edge Shadows");
checkbox.click();
h.run_steps(2);