From 0b77f4cb771ba903233d9f8d92f5980545dd1ee8 Mon Sep 17 00:00:00 2001 From: mtlcl410 <2368091+mtlcl410@users.noreply.github.com> Date: Sat, 17 Oct 2026 20:21:22 +0800 Subject: [PATCH] fix(ui): Fill & Sign font size resizes the selected text (#1274) The Font size control on the Fill & Sign bar only set the size of text typed afterwards; text already placed and picked up kept its size, so the only way to resize it was to type it again. With a placed Fill & Sign text or date selected, a size typed into the control (or the end of a drag) now applies to it through Edit::FontSizeAnnotation, one undo step per change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RUNQSPVXx3dDBabRZHAnjz --- crates/ui-egui/src/canvas.rs | 19 ++++++++++- crates/ui-egui/tests/fill_sign.rs | 54 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 0acab64a0..f39fbc24b 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -4582,12 +4582,29 @@ fn quick_bar(app: &mut PdfCraftApp, area: Rect, ui: &mut egui::Ui) { }); if matches!(current_fill, Some(crate::fill_sign::FillTool::Text | crate::fill_sign::FillTool::Date)) { ui.label(tl!("Font size:")); - ui.add( + let size = ui.add( egui::DragValue::new(&mut app.fill_text_size) .range(crate::fill_sign::MIN_TEXT_SIZE..=crate::fill_sign::MAX_TEXT_SIZE) .speed(0.25) .suffix(" pt"), ); + // #1274: the size also applies to the Fill & Sign text that is selected, + // once per change (a typed value, or the end of a drag), so a drag adds + // one undo step and not one per frame. + if ((size.changed() && !size.dragged()) || size.drag_stopped()) + && let Some((index, id)) = app.active_ids() + && let Some((page, annotation)) = app.views.get(index).and_then(|view| view.comments.selected) + && app.session.get(id).is_some_and(|doc| { + doc.allows_annotation() + && doc + .info + .annotations + .iter() + .any(|a| a.page == page && a.index == annotation && a.fill_sign && a.subtype == "FreeText" && !a.locked) + }) + { + app.apply_edit(Edit::FontSizeAnnotation { page, index: annotation, size: app.fill_text_size }); + } } if let QuickTool::Comment(tool) = app.quick_tool { let (r, _) = ui.allocate_exact_size(vec2(32.0, 9.0), Sense::hover()); diff --git a/crates/ui-egui/tests/fill_sign.rs b/crates/ui-egui/tests/fill_sign.rs index 27fd6dd8a..8f4019fe6 100644 --- a/crates/ui-egui/tests/fill_sign.rs +++ b/crates/ui-egui/tests/fill_sign.rs @@ -168,6 +168,60 @@ fn fill_text_size_controls_new_text_and_survives_settings_restore() { assert_eq!(restored.fill_text_size, 24.0, "invalid settings do not change the size"); } +/// #1274: with a placed Fill & Sign text selected, the Font size control resizes that text, +/// not only text typed afterwards; with nothing selected it changes nothing on the page. +#[test] +fn fill_text_size_resizes_the_selected_text() { + let mut h = harness(); + h.state_mut().execute("sign.fill.text"); + click(&mut h, 50.0, 250.0); + h.event(egui::Event::Text("Resize me".into())); + h.run_steps(1); + h.key_press(egui::Key::Enter); + h.run_steps(3); + let height = |h: &Harness<'static, PdfCraftApp>| { + let s = h.state(); + let a = s.session.get(s.views[0].id).unwrap().info.annotations.iter().find(|a| a.contents.as_deref() == Some("Resize me")).cloned().unwrap(); + a.rect[3] - a.rect[1] + }; + let before = height(&h); + let set_size = |h: &mut Harness<'static, PdfCraftApp>, value: &str| { + h.query_all_by_role(egui::accesskit::Role::SpinButton) + .find(|n| n.value().is_some_and(|v| v.ends_with(" pt"))) + .expect("the Font size control") + .click(); + h.run_steps(2); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text(value.into())); + h.run_steps(1); + h.key_press(egui::Key::Enter); + h.run_steps(4); + }; + // Nothing selected: only the size for new text changes. + h.state_mut().views[0].comments.selected = None; + set_size(&mut h, "18"); + assert_eq!(h.state().fill_text_size, 18.0); + assert_eq!(height(&h), before, "an unselected placed text keeps its size"); + // The placed text picked up with the Add text tool, then resized. + let annotation = { + let s = h.state(); + s.session + .get(s.views[0].id) + .unwrap() + .info + .annotations + .iter() + .find(|a| a.contents.as_deref() == Some("Resize me")) + .map(|a| (a.page, a.index)) + .unwrap() + }; + h.state_mut().views[0].comments.selected = Some(annotation); + set_size(&mut h, "36"); + assert_eq!(h.state().fill_text_size, 36.0); + let after = height(&h); + assert!(after > before * 2.0, "36 pt text has a taller box than 10 pt text: {before} -> {after}"); +} + #[test] fn the_type_box_grows_as_text_is_typed() { let mut h = harness();