From 6b7abc61d117278162c173b250a44ac7ee16159d Mon Sep 17 00:00:00 2001 From: mtlcl410 Date: Thu, 15 Oct 2026 14:30:42 +0800 Subject: [PATCH] fix(edit): flattening keeps a widget it cannot draw and an undrawn reply (#1794) (#1934) A widget with no appearance to draw (none stored, or none for its selected state) was removed from the page and the field tree with nothing in its place, so the field's value was lost; a reply kept because it could not be drawn was then deleted anyway as a reply of the flattened comment. Both now stay as they are. A widget whose appearance draws nothing is still removed, as is a reply note's empty appearance with its comment. Claude-Session: https://claude.ai/code/session_01RUNQSPVXx3dDBabRZHAnjz Co-authored-by: Claude Fable 5.1 --- crates/edit/src/flatten.rs | 26 ++++++++++++++---- crates/edit/src/tests.rs | 52 ++++++++++++++++++++++++++++++++++++ parity/acrobat-features.toml | 8 +++--- 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/crates/edit/src/flatten.rs b/crates/edit/src/flatten.rs index a3f6c886a2..8202c18d83 100644 --- a/crates/edit/src/flatten.rs +++ b/crates/edit/src/flatten.rs @@ -6,7 +6,8 @@ //! the appearance's bounding box, transformed by its `/Matrix`, mapped onto `/Rect`). Hidden //! annotations are left alone; links are kept (they have no ink and stay clickable). Flattened //! comments take their pop-ups and replies with them; flattened widgets are removed from the -//! form's field tree. +//! form's field tree. An annotation whose appearance cannot be drawn is not flattened: it stays +//! as it is, so no comment or field value is lost with nothing in its place. use std::collections::HashSet; @@ -154,6 +155,8 @@ fn flatten_which(doc: &mut Document, pages: &[usize], which: Which) -> Result = HashSet::new(); let mut gone_inline: HashSet = HashSet::new(); + // Selected, but nothing was drawn for it: it stays, pop-up and reply handling included. + let mut undrawn: HashSet = HashSet::new(); // A viewer draws many comments from their dictionary even when the file stores no // appearance (notes, FreeText, ink, stamps…). Build the appearance it would show, so // flattening keeps a comment that still has ink on screen instead of deleting it. @@ -199,9 +202,18 @@ fn flatten_which(doc: &mut Document, pages: &[usize], which: Which) -> Result { @@ -218,9 +230,13 @@ fn flatten_which(doc: &mut Document, pages: &[usize], which: Which) -> Result