diff --git a/crates/ui-egui/src/editing.rs b/crates/ui-egui/src/editing.rs index a28a5485c9..e8b9aad57b 100644 --- a/crates/ui-egui/src/editing.rs +++ b/crates/ui-egui/src/editing.rs @@ -57,6 +57,14 @@ impl PdfCraftApp { let newest = info.annotations.iter().filter(|x| x.page == a.page && x.in_reply_to.is_none()).map(|x| x.index).max(); view.comments.selected = newest.map(|n| (a.page, n)); view.comments.reveal = true; + // A new highlight opens its note for typing straight away, as in Acrobat, + // unless a note typed into another card is still unsaved. + if let (pdfcraft_engine::Shape::TextMarkup { kind: pdfcraft_engine::Markup::Highlight, .. }, Some(n)) = (&a.shape, newest) + && a.contents.is_empty() + && view.comments.editing.as_ref().is_none_or(|(_, _, text)| text.is_empty()) + { + view.comments.editing = Some((a.page, n, String::new())); + } } Edit::DeleteAnnotation { .. } => view.comments.selected = None, _ => {} diff --git a/crates/ui-egui/tests/comments.rs b/crates/ui-egui/tests/comments.rs index e596e74fcf..cb1dc9a3f2 100644 --- a/crates/ui-egui/tests/comments.rs +++ b/crates/ui-egui/tests/comments.rs @@ -116,6 +116,29 @@ fn dragging_over_text_with_the_highlighter_highlights_it() { assert_eq!(h.state().session.get(h.state().views[0].id).unwrap().can_undo(), Some("Add highlight")); } +#[test] +fn a_new_highlight_opens_its_note_for_typing() { + let mut h = harness(|app| app.set_option("quick", "highlight").unwrap()); + assert_eq!(h.state().views[0].comments.editing, None); + let (a, b) = { + let v = &h.state().views[0]; + (v.glyph_screen_pos(0, 4).expect("text layer"), v.glyph_screen_pos(0, 14).expect("glyph")) + }; + drag(&mut h, a, b); + assert_eq!(comments(&h).len(), 1); + assert_eq!(h.state().views[0].comments.editing, Some((0, 0, String::new())), "the Comments panel edits the new highlight"); + // An area highlight opens its note too, replacing the empty one. + drag_pt(&mut h, (40.0, 100.0), (140.0, 40.0)); + assert_eq!(comments(&h).len(), 2); + assert_eq!(h.state().views[0].comments.editing, Some((0, 1, String::new()))); + // A note being typed is kept: the next highlight is only selected. + h.state_mut().views[0].comments.editing = Some((0, 1, "typed".into())); + drag_pt(&mut h, (160.0, 100.0), (260.0, 40.0)); + assert_eq!(comments(&h).len(), 3); + assert_eq!(h.state().views[0].comments.selected, Some((0, 2))); + assert_eq!(h.state().views[0].comments.editing, Some((0, 1, "typed".into()))); +} + #[test] fn a_selection_made_first_is_marked_when_a_tool_is_picked() { let mut h = harness(|_| {}); diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 647ddbf180..6cc6eaef0f 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -3494,8 +3494,8 @@ milestone = "M5" status = "shipped" commands = ["comment.highlight"] tools = ["comment_add"] -evidence = ["crates/ui-egui/tests/comments.rs::dragging_over_text_with_the_highlighter_highlights_it", "crates/engine/src/tests.rs::highlight_multiplies_over_text"] -notes = "drag over text, or pick the tool with text selected; agents can highlight by text search" +evidence = ["crates/ui-egui/tests/comments.rs::dragging_over_text_with_the_highlighter_highlights_it", "crates/ui-egui/tests/comments.rs::a_new_highlight_opens_its_note_for_typing", "crates/engine/src/tests.rs::highlight_multiplies_over_text"] +notes = "drag over text, or pick the tool with text selected; a new highlight opens its note for typing in the Comments panel; agents can highlight by text search" [[feature]] id = "comment.underline"