Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

fix(comments): Undo and Redo close the panel's inline editor

aleheladeb9c1cf233
diff --git a/ROADMAP.md b/ROADMAP.md
index 7708f1ae0..6f580f609 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -201,7 +201,7 @@ Ranked; detail and the full milestone table in [docs/roadmap.md](docs/roadmap.md
## Progress log
- **2026-10-27 (M10, OCR models):** Model staging downloads and verifies the ONNX pair after the upstream RTEN URL brownout; runtime discovery prefers complete ONNX pairs per directory, retains complete RTEN fallback and preserves directory precedence.
-- **2026-10-25 (M5, comment replies):** One reply can be deleted from the Comments panel without its thread. On the selected card each reply has its own "…" menu (Edit, Copy text, Delete); Delete takes that reply with its pop-up and the replies to it, as `comment_delete` already did headlessly, and the comment and its other replies stay. The card stays selected, and the panel's editor stays open, on what they were on though the delete moved it in `/Annots`. A locked reply can't be deleted. Estimates unchanged.
+- **2026-10-25 (M5, comment replies):** One reply can be deleted from the Comments panel without its thread. On the selected card each reply has its own "…" menu (Edit, Copy text, Delete); Delete takes that reply with its pop-up and the replies to it, as `comment_delete` already did headlessly, and the comment and its other replies stay. The card stays selected, and the panel's editor stays open, on what they were on though the delete moved it in `/Annots`. Undo and Redo close the editor, since either can move what it was open on. A locked reply can't be deleted. Estimates unchanged.
- **2026-10-24 (M10, #4158 partial):** Word, HTML, RTF and PowerPoint export keep a block that continues another on its line (an italic case name, a link, a superscript) as a run in its own style inside that paragraph, with the source's word space, instead of a paragraph of its own. Style changes that wrap onto the next line still split paragraphs (the reading blocks keep style boundaries). Estimates unchanged.
- **2026-10-24 (M3, window move on Wayland, #3970 follow-up):** After a move or resize by PdfCraft's own title bar or edges, the button release given back to egui goes before the pointer leaving the window, so hover no longer sticks at the old place until the pointer moves. Found by CodeRabbit in review of #3970; a unit test covers it. Estimates unchanged.
- **2026-10-24 (M14, #4253):** The annotation quick bar remembers Keep tool selected across restarts, including unpinning. Old and malformed settings keep safe defaults; the opt-in UI control channel reads and changes the same preference. Estimates unchanged.
diff --git a/crates/ui-egui/src/editing.rs b/crates/ui-egui/src/editing.rs
index 1ee4c7a6f..7e5ea8ed6 100644
--- a/crates/ui-egui/src/editing.rs
+++ b/crates/ui-egui/src/editing.rs
@@ -232,7 +232,7 @@ impl PdfCraftApp {
if let Some(doc) = self.session.get(id) {
self.views[i].document_changed(&doc.info);
}
- self.views[i].comments.selected = None;
+ self.views[i].comments.history_stepped();
let label = crate::i18n::edit_label(&label);
if undo {
self.notify_fmt("Undid {label}", &[("label", &label)]);
diff --git a/crates/ui-egui/src/tools/comments/state.rs b/crates/ui-egui/src/tools/comments/state.rs
index db4504190..a886e2dfd 100644
--- a/crates/ui-egui/src/tools/comments/state.rs
+++ b/crates/ui-egui/src/tools/comments/state.rs
@@ -230,6 +230,16 @@ impl CommentView {
self.editor_focus = None;
}
}
+
+ /// Undo or Redo just ran. Either may have put annotations back or taken them away, on any
+ /// page, so a (page, index) held here may now name another one. The selection and the inline
+ /// editor close, its unsaved text with it, rather than Save writing that text over whatever
+ /// took its place.
+ pub(crate) fn history_stepped(&mut self) {
+ self.selected = None;
+ self.editing = None;
+ self.editor_focus = None;
+ }
}
/// Where the annotation at `keep` is once the one at `gone` was deleted, or `None` when it went
diff --git a/crates/ui-egui/tests/it/comments.rs b/crates/ui-egui/tests/it/comments.rs
index 2fcc2299d..70326c2f3 100644
--- a/crates/ui-egui/tests/it/comments.rs
+++ b/crates/ui-egui/tests/it/comments.rs
@@ -1426,6 +1426,71 @@ fn one_reply_is_deleted_from_its_menu_and_the_thread_stays() {
h.get_by_label("Wrong reply");
}
+// Contributor-original PDF: a comment and its replies A, B and C, in that `/Annots` order.
+const THREE_REPLIES: &[u8] = b"%PDF-1.7
+1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj
+2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj
+3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 300 200] /Annots [4 0 R 5 0 R 6 0 R 7 0 R] >> endobj
+4 0 obj << /Type /Annot /Subtype /Text /Rect [20 140 40 160] /NM (note) /T (Ben) /Contents (The comment) >> endobj
+5 0 obj << /Type /Annot /Subtype /Text /Rect [20 140 40 160] /NM (a) /IRT 4 0 R /T (Cat) /Contents (Reply A) >> endobj
+6 0 obj << /Type /Annot /Subtype /Text /Rect [20 140 40 160] /NM (b) /IRT 4 0 R /T (Dan) /Contents (Reply B) >> endobj
+7 0 obj << /Type /Annot /Subtype /Text /Rect [20 140 40 160] /NM (c) /IRT 4 0 R /T (Eve) /Contents (Reply C) >> endobj
+trailer << /Root 1 0 R >>
+%%EOF";
+
+/// Opens the inline editor on the reply that shows `text`, from its "…" menu, and types `draft`
+/// into it without saving.
+fn draft_reply(h: &mut Harness<'static, PdfCraftApp>, text: &str, draft: &str) {
+ reply_options(h, text).click();
+ h.run_steps(2);
+ h.query_all_by_label("Edit").last().expect("the reply menu's Edit, after the toolbar tab").click();
+ h.run_steps(2);
+ let editor = h.query_all_by(|n| n.role() == Role::MultilineTextInput && n.placeholder() != Some("Add a reply")).next().expect("reply editor");
+ editor.click();
+ h.run_steps(1);
+ h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
+ h.event(egui::Event::Text(draft.into()));
+ h.run_steps(2);
+}
+
+/// A reply's inline editor, left open with a draft, closes on Undo and on Redo. Either can put
+/// a reply back in its place or take one away, and the editor would have saved the draft over
+/// whichever reply took that place: reply A after delete → Undo, reply C after Redo.
+#[test]
+fn undo_and_redo_close_a_reply_editor_left_open() {
+ let mut h = harness_with_bytes(THREE_REPLIES.to_vec(), |app| {
+ app.set_option("panel", "comments").unwrap();
+ app.views[0].comments.selected = Some((0, 0));
+ });
+ let texts = |h: &Harness<'static, PdfCraftApp>| -> Vec<String> { comments(h).iter().filter_map(|a| a.contents.clone()).collect() };
+ let all = ["The comment", "Reply A", "Reply B", "Reply C"];
+ assert_eq!(texts(&h), all);
+
+ draft_reply(&mut h, "Reply B", "B's draft");
+ reply_options(&h, "Reply A").click();
+ h.run_steps(2);
+ h.get_by_label("Delete").click();
+ h.run_steps(3);
+ assert_eq!(texts(&h), ["The comment", "Reply B", "Reply C"]);
+ assert_eq!(h.state().views[0].comments.editing, Some((0, 1, "B's draft".to_string())), "the editor follows B up");
+
+ h.state_mut().undo();
+ h.run_steps(3);
+ assert_eq!(texts(&h), all, "undo puts A back where B's editor now points");
+ assert_eq!(h.state().views[0].comments.editing, None, "the editor closes on undo");
+ assert_eq!(h.query_all_by_label("Save").count(), 0, "no draft is left to save over A");
+
+ h.state_mut().views[0].comments.selected = Some((0, 0));
+ h.run_steps(2);
+ draft_reply(&mut h, "Reply B", "B's draft");
+ assert_eq!(h.state().views[0].comments.editing, Some((0, 2, "B's draft".to_string())));
+ h.state_mut().redo();
+ h.run_steps(3);
+ assert_eq!(texts(&h), ["The comment", "Reply B", "Reply C"], "redo deletes A again, and C takes B's place");
+ assert_eq!(h.state().views[0].comments.editing, None, "the editor closes on redo");
+ assert_eq!(h.query_all_by_label("Save").count(), 0, "no draft is left to save over C");
+}
+
#[test]
fn the_header_names_no_replies_when_there_are_none() {
let h = harness_with_bytes(PER_PAGE_NAMES.to_vec(), |app| {
diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml
index 52d6fa0c7..f7e95de61 100644
--- a/parity/acrobat-features.toml
+++ b/parity/acrobat-features.toml
@@ -4051,8 +4051,8 @@ milestone = "M5"
status = "shipped"
commands = ["comment.list"]
tools = ["comment_edit"]
-evidence = ["crates/annot/src/tests.rs::text_box_text_and_colour_changes_are_drawn", "crates/annot/src/tests.rs::editing_a_text_box_refits_its_rectangle", "crates/automation/tests/it/automation.rs::comments_through_tools", "crates/ui-egui/tests/it/comments.rs::ctrl_enter_posts_a_highlight_comment_and_shift_enter_adds_a_line", "crates/ui-egui/tests/it/comments.rs::one_reply_is_deleted_from_its_menu_and_the_thread_stays"]
-notes = "double-click a comment or card, or Edit in the menus (a reply from its own \"…\" menu); Ctrl+Enter (also Command+Enter) saves text in the focused comment editor, Shift+Enter adds a newline; a text box's rectangle follows the new text (wrap width and top edge stay, the height fits the wrapped lines)"
+evidence = ["crates/annot/src/tests.rs::text_box_text_and_colour_changes_are_drawn", "crates/annot/src/tests.rs::editing_a_text_box_refits_its_rectangle", "crates/automation/tests/it/automation.rs::comments_through_tools", "crates/ui-egui/tests/it/comments.rs::ctrl_enter_posts_a_highlight_comment_and_shift_enter_adds_a_line", "crates/ui-egui/tests/it/comments.rs::one_reply_is_deleted_from_its_menu_and_the_thread_stays", "crates/ui-egui/tests/it/comments.rs::undo_and_redo_close_a_reply_editor_left_open"]
+notes = "double-click a comment or card, or Edit in the menus (a reply from its own \"…\" menu); Ctrl+Enter (also Command+Enter) saves text in the focused comment editor, Shift+Enter adds a newline; a text box's rectangle follows the new text (wrap width and top edge stay, the height fits the wrapped lines). Undo or Redo closes the panel's editor without saving it, since either can move the comment it was open on"
[[feature]]
id = "comment.copy-comment-text"