From 280f2439ec34dd82f6feb8416a2fc0898c14261f Mon Sep 17 00:00:00 2001 From: vangel76 Date: Wed, 14 Oct 2026 23:03:14 +0200 Subject: [PATCH] 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 --- crates/ui-egui/src/appearance.rs | 9 ++++++++ crates/ui-egui/src/canvas.rs | 4 ++-- crates/ui-egui/tests/view.rs | 38 +++++++++++++++++++++++++------- parity/acrobat-features.toml | 4 ++-- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/appearance.rs b/crates/ui-egui/src/appearance.rs index 0d607cc91..536d8e4d9 100644 --- a/crates/ui-egui/src/appearance.rs +++ b/crates/ui-egui/src/appearance.rs @@ -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(); diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index eb9244a28..bd408f401 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -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 } } } diff --git a/crates/ui-egui/tests/view.rs b/crates/ui-egui/tests/view.rs index 9cf99021a..713702b13 100644 --- a/crates/ui-egui/tests/view.rs +++ b/crates/ui-egui/tests/view.rs @@ -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] diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 7aca7d5c8..7d95c7098 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -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"