Comments: the composer refocuses after its page was off screen (#4021)

When the whole page left the screen, `composer` returned before it set
`focus`, so the editor didn't take the keyboard again when the page came
back (review on #4095). That path now asks for the focus too.

Test `the_composer_takes_the_keyboard_back_after_its_page_was_off_screen`
scrolls page 1 off the screen and back; it fails without the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mmmaarian03-crypto
2026-10-23 08:57:40 +03:00
co-authored by Claude Opus 5.5
parent d6ba2413ba
commit cdc0834f34
2 changed files with 26 additions and 1 deletions
+4 -1
View File
@@ -1559,7 +1559,10 @@ pub(crate) fn composer(ctx: &egui::Context, view: &mut DocView, info: &DocInfo,
let c = view.comments.composer.as_ref()?;
let page = c.page;
let Some(xf) = view.page_xform(page) else {
// Scrolled away: keep the draft until the page is back.
// Scrolled away: keep the draft until the page is back, and give it the keyboard then.
if let Some(c) = view.comments.composer.as_mut() {
c.focus = true;
}
return None;
};
let cx = PageCx { page, xf: &xf, info, tool: QuickTool::Select, prefs, allowed: true, hidden: false, redact_mark: ([0.89, 0.13, 0.13], 1.0) };
+22
View File
@@ -703,6 +703,28 @@ fn the_composer_hides_while_its_comment_is_scrolled_away() {
assert_eq!(h.state().views[0].comments.composer.as_ref().map(|c| c.text.as_str()), Some("Draft"));
}
/// With its whole page scrolled off the screen the composer keeps its draft, and the editor takes
/// the keyboard again when the page comes back (#4021).
#[test]
fn the_composer_takes_the_keyboard_back_after_its_page_was_off_screen() {
let mut h = harness(|app| app.set_option("quick", "note").unwrap());
click_pt(&mut h, (250.0, 180.0));
field(&h, "Add a comment").type_text("Draft");
h.run_steps(2);
let editor_focused =
|h: &Harness<'static, PdfCraftApp>| h.query_all_by(|n| n.role() == egui::accesskit::Role::MultilineTextInput).any(|n| n.is_focused());
assert!(editor_focused(&h), "the new note's editor has the keyboard");
let viewport = h.state().views[0].viewport_rect();
h.state_mut().views[0].goto = Some((1, 0.6));
h.run_steps(4);
assert!(h.state().views[0].page_screen_rect(0).is_none_or(|r| r.bottom() < viewport.top()), "page 1 is off the screen");
assert!(!editor_focused(&h), "nothing to type into while the page is away");
h.state_mut().views[0].goto = Some((0, 0.0));
h.run_steps(4);
assert_eq!(h.state().views[0].comments.composer.as_ref().map(|c| c.text.as_str()), Some("Draft"));
assert!(editor_focused(&h), "the editor has the keyboard again");
}
/// The rectangle of the comment whose text starts with `text`.
fn rect_of(h: &Harness<'static, PdfCraftApp>, text: &str) -> [f32; 4] {
let c = comments(h);