M5.7: pressing the Fill & Sign size slider without moving it adds no undo step

The slider senses drags only, so a press and release counts as a finished
drag even when the value did not move. The edit is now skipped when the
selected text already has that size, compared to the three decimals the size
is saved with.
This commit is contained in:
Andrew committed 2026-11-03 05:23:14 -07:00
1 parent 546a9d90a5
commit 0a8aa374eb
2 files changed
+65 -2

No files matched your search

+9 -2
View File
@@ -343,8 +343,15 @@ fn active_tool_controls(ui: &mut egui::Ui, app: &mut PdfCraftApp, t: &Tokens, ve
(size.changed() && !size.dragged()) || size.drag_stopped()
})
.is_some_and(|popup| popup.inner);
if resized && let Some((page, index)) = selected_fill_text(app) {
app.apply_edit(Edit::FontSizeAnnotation { page, index, size: app.fill_text_size });
let size = app.fill_text_size;
if resized
&& let Some((page, index)) = selected_fill_text(app)
&& app
.active_ids()
.and_then(|(_, id)| app.session.get(id)?.comment_props(page, index)?.font_size)
.is_none_or(|stored| format!("{stored:.3}") != format!("{size:.3}"))
{
app.apply_edit(Edit::FontSizeAnnotation { page, index, size });
}
}
if let QuickTool::Comment(tool) = app.quick_tool {
+56
View File
@@ -1896,6 +1896,62 @@ fn dragging_the_fill_text_size_slider_is_one_undo_step() {
assert_eq!(placed_height(&h, "Drag me"), height, "one undo takes the whole drag back");
}
#[test]
fn pressing_the_fill_text_size_slider_without_moving_it_adds_no_undo_step() {
let mut h = harness();
place_selected_text(&mut h, "Hold me");
let height = placed_height(&h, "Hold me");
h.get_by_label("Font size").click();
h.run_steps(2);
let slider = h.get_by_role(egui::accesskit::Role::Slider).rect();
let at = pos2(slider.min.x + (slider.max.x - slider.min.x) * 0.75, (slider.min.y + slider.max.y) / 2.0);
let press = |h: &mut Harness<'static, PdfCraftApp>| {
h.hover_at(at);
h.run_steps(1);
h.drag_at(at);
h.run_steps(1);
h.drop_at(at);
h.run_steps(3);
};
press(&mut h);
let resized = placed_height(&h, "Hold me");
assert!(resized > height, "the first press moves the size: {height} -> {resized}");
press(&mut h);
assert_eq!(placed_height(&h, "Hold me"), resized);
h.state_mut().execute("edit.undo");
h.run_steps(3);
assert_eq!(placed_height(&h, "Hold me"), height, "one undo takes back the only change; the second press added no step");
}
#[test]
fn typing_a_fill_text_size_that_rounds_to_the_stored_one_adds_no_undo_step() {
let mut h = harness();
place_selected_text(&mut h, "Round me");
let height = placed_height(&h, "Round me");
h.get_by_label("Font size").click();
h.run_steps(2);
let type_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);
};
type_size(&mut h, "36.1234");
let resized = placed_height(&h, "Round me");
assert!(resized > height, "the first size applies: {height} -> {resized}");
type_size(&mut h, "36.1231");
assert_eq!(h.state().fill_text_size, 36.1231);
h.state_mut().execute("edit.undo");
h.run_steps(3);
assert_eq!(placed_height(&h, "Round me"), height, "one undo takes back the only change; the rounded retype added no step");
}
#[test]
fn the_fill_colour_dot_recolours_the_selected_text() {
let mut h = harness();