Preferences: field highlights on by default, with a toggle in Appearance (#2273)

New settings start with Highlight fields on. A stored choice is kept; a missing or
malformed value falls back to on. Preferences > Appearance gets the checkbox.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
vangel76
2026-10-20 01:10:07 +02:00
co-authored by Claude Sonnet 5.5
parent ec0a965074
commit 280f2439ec
4 changed files with 43 additions and 12 deletions
+9
View File
@@ -139,6 +139,9 @@ pub fn preferences_section(ui: &mut egui::Ui, app: &mut PdfCraftApp, t: &Tokens)
app.execute(mode_command(ThemePreference::Dark));
}
});
ui.add_space(4.0);
// Acrobat's "Highlight existing fields": shared with the toggle in the form bar.
ui.add(crate::widgets::checkbox(&mut app.view_defaults.highlight_fields, tl!("Highlight fields")));
}
#[cfg(test)]
@@ -176,6 +179,12 @@ mod tests {
h.render().unwrap().save(path).unwrap();
}
// The field-highlight preference is on for new settings, and the box turns it off.
assert!(h.state().view_defaults.highlight_fields);
h.get_by_label("Highlight fields").click();
h.run();
assert!(!h.state().view_defaults.highlight_fields);
let combo = egui::accesskit::Role::ComboBox;
h.get_by_role(combo).click();
h.run();
+2 -2
View File
@@ -174,14 +174,14 @@ pub struct ViewDefaults {
/// The zoom with [`Fit::None`] (1.0 = 100%).
pub zoom: f32,
/// Highlight existing fields: a preference in Acrobat, so it carries over to the next
/// document and the next session.
/// document and the next session. On for new settings; a stored choice wins.
pub highlight_fields: bool,
}
impl Default for ViewDefaults {
fn default() -> Self {
// Single page, scrolling continuously at fit width: the earlier "continuous" default.
Self { layout: PageLayout::Single, continuous: true, fit: Fit::Width, zoom: 1.0, highlight_fields: false }
Self { layout: PageLayout::Single, continuous: true, fit: Fit::Width, zoom: 1.0, highlight_fields: true }
}
}
+30 -8
View File
@@ -1059,6 +1059,8 @@ fn highlight_fields_tints_the_field_area() {
let _gpu = gpu();
let mut h = form_harness();
h.state_mut().set_option("panel", "none").unwrap();
// Highlighting is on by default; start from plain fields.
h.state_mut().set_option("fields", "off").unwrap();
for _ in 0..100 {
h.run_steps(2);
if !h.state().render_pending() {
@@ -1136,27 +1138,47 @@ fn required_radio_buttons_get_a_round_red_border() {
assert!(!stroke(at(50.3, 339.7)), "the widget's corner, outside the circle, is not: {:?}", at(50.3, 339.7));
}
/// Acrobat's Highlight existing fields is a preference, not a per-document choice: turned on
/// once, the next document (and the next session) opens with fields highlighted.
/// Acrobat's Highlight existing fields is a preference, not a per-document choice: turned off
/// once, the next document (and the next session) opens with fields plain. New settings start
/// with it on.
#[test]
fn field_highlighting_is_remembered() {
fn field_highlighting_is_on_by_default_and_remembered() {
use egui_kittest::kittest::Queryable;
let mut h = form_harness();
h.state_mut().set_option("panel", "none").unwrap();
h.run_steps(4);
assert!(!h.state().views[0].highlight_fields, "off by default");
h.get_by_label("Highlight fields").click();
assert!(h.state().views[0].highlight_fields, "on by default");
h.get_by_label("Hide field highlights").click();
h.run_steps(4);
assert!(h.state().views[0].highlight_fields);
assert!(!h.state().views[0].highlight_fields);
h.state_mut().open_bytes("radios.pdf", None, RADIOS.to_vec()).expect("opens");
h.run_steps(4);
assert!(h.state().views[1].highlight_fields, "the next document opens highlighted");
assert!(!h.state().views[1].highlight_fields, "the next document opens plain");
let saved = h.state().persist();
let mut next = PdfCraftApp::new();
next.set_option("language", "en").unwrap();
next.restore(&saved);
next.open_bytes("form.pdf", None, FORM.to_vec()).expect("opens");
assert!(next.views[0].highlight_fields, "and so does the next session");
assert!(!next.views[0].highlight_fields, "and so does the next session");
}
/// Settings saved before the default changed keep their stored choice; a missing or malformed
/// value falls back to the default instead of failing.
#[test]
fn stored_field_highlight_choice_wins_over_the_default() {
for (stored, expected) in [
(r#"{"highlight_fields": false}"#, false),
(r#"{"highlight_fields": true}"#, true),
(r#"{}"#, true),
(r#"{"highlight_fields": "no"}"#, true),
(r#"{"highlight_fields": null}"#, true),
] {
let mut app = PdfCraftApp::new();
app.set_option("language", "en").unwrap();
app.restore(stored);
app.open_bytes("form.pdf", None, FORM.to_vec()).expect("opens");
assert_eq!(app.views[0].highlight_fields, expected, "{stored}");
}
}
#[test]
+2 -2
View File
@@ -4392,8 +4392,8 @@ milestone = "M3"
status = "shipped"
commands = []
tools = []
evidence = ["crates/ui-egui/tests/view.rs::highlight_fields_tints_the_field_area", "crates/ui-egui/tests/view.rs::required_radio_buttons_get_a_round_red_border", "crates/ui-egui/tests/view.rs::field_highlighting_is_remembered", "crates/ui-egui/tests/editing.rs::a_secured_form_shows_its_form_notice_and_its_security"]
notes = "offered on secured forms too; remembered for the next document and session; required fields get a red border (round for radio buttons); the tint is drawn over the field, where Acrobat paints the highlight colour behind it"
evidence = ["crates/ui-egui/tests/view.rs::highlight_fields_tints_the_field_area", "crates/ui-egui/tests/view.rs::required_radio_buttons_get_a_round_red_border", "crates/ui-egui/tests/view.rs::field_highlighting_is_on_by_default_and_remembered", "crates/ui-egui/tests/view.rs::stored_field_highlight_choice_wins_over_the_default", "crates/ui-egui/tests/editing.rs::a_secured_form_shows_its_form_notice_and_its_security"]
notes = "offered on secured forms too; on by default for new settings (a stored choice is kept) and remembered for the next document and session; toggled from the form bar and from Preferences > Appearance, where it sets the default for documents opened afterwards; required fields get a red border (round for radio buttons); the tint is drawn over the field, where Acrobat paints the highlight colour behind it"
[[feature]]
id = "form.field-appearance-display"