mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-14 19:27:04 -04:00
Adding a highlight selected its card in the Comments panel but left the note closed; the text field only appeared after double-clicking the card. Acrobat opens the note for typing as soon as the highlight is made. apply_edit now opens the inline editor for a new highlight (text drag, selection then tool, area highlight all pass through it), unless a note typed into another card is still unsaved, so that text is never dropped.
This commit is contained in:
1 parent
bc1d67cb61
commit
271139bd3b
3 files changed
+33
-2
No files matched your search
@@ -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,
|
||||
_ => {}
|
||||
|
||||
@@ -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(|_| {});
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user