diff --git a/crates/engine/src/cmd/options.rs b/crates/engine/src/cmd/options.rs index a829f4c07..fea758be4 100644 --- a/crates/engine/src/cmd/options.rs +++ b/crates/engine/src/cmd/options.rs @@ -176,6 +176,7 @@ fn options(s: &mut Session, v: &Value) -> CmdResult { } if let Some(b) = check_spelling { s.view.proofing = b; + s.prefs.check_spelling = b; } for w in &add { wordcraft_proof::add_word(w); diff --git a/crates/engine/src/cmd/review.rs b/crates/engine/src/cmd/review.rs index 2ba4a79d6..9316b6014 100644 --- a/crates/engine/src/cmd/review.rs +++ b/crates/engine/src/cmd/review.rs @@ -104,6 +104,7 @@ pub fn specs() -> Vec { .params(r#"{"text": string}"#), CommandSpec::new("review.proofing", "Check Spelling as You Type", "File › Options › Proofing", |s, v| { s.view.proofing = p::bool(v, "value").unwrap_or(!s.view.proofing); + s.prefs.check_spelling = s.view.proofing; Ok(json!({"value": s.view.proofing})) }) .pure(), diff --git a/crates/engine/src/session.rs b/crates/engine/src/session.rs index 5d6aacaae..1577b6ecd 100644 --- a/crates/engine/src/session.rs +++ b/crates/engine/src/session.rs @@ -516,6 +516,9 @@ pub struct Prefs { pub marks: wordcraft_layout::display::FormattingMarks, /// Mark grammar errors as you type (with Check spelling as you type on). pub mark_grammar: bool, + /// Check spelling as you type (File › Options › Proofing). The live value is + /// `ViewState::proofing`; this is the copy that is saved and restored (#1792). + pub check_spelling: bool, pub ignore_uppercase: bool, pub ignore_numbers: bool, pub ignore_internet: bool, @@ -539,6 +542,7 @@ impl Default for Prefs { dictionaries_folder: None, marks: Default::default(), mark_grammar: true, + check_spelling: true, ignore_uppercase: true, ignore_numbers: true, ignore_internet: true, diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 6f030d301..4ce89ff20 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -692,6 +692,8 @@ impl WordApp { } } self.session.prefs = std::mem::take(&mut self.ui.editing); + // Check spelling as you type follows the saved preference (#1792). + self.session.view.proofing = self.session.prefs.check_spelling; // The saved dictionaries folder (#1063) is searched from the start. if let Some(f) = self.session.prefs.dictionaries_folder.as_deref() { wordcraft_engine::cmd::options::use_dictionaries_folder(Some(f)); diff --git a/crates/ui-egui/src/options.rs b/crates/ui-egui/src/options.rs index 635757eca..925d3350c 100644 --- a/crates/ui-egui/src/options.rs +++ b/crates/ui-egui/src/options.rs @@ -772,6 +772,20 @@ mod tests { assert_eq!(wordcraft_engine::proof::hunspell::search_dirs(None).first(), Some(&dir), "searched first"); } + /// #1792: Check spelling as you type is saved with the other proofing choices, so after a + /// restart the box comes back the way the user left it. + #[test] + fn check_spelling_survives_a_restart() { + let mut a = app(); + a.run("file.options", json!({"checkSpelling": false})).unwrap(); + assert!(!a.session.view.proofing, "off right away"); + let saved = serde_json::to_value(a.prefs()).unwrap(); + assert_eq!(saved["editing"]["checkSpelling"], false, "saved in ui.json"); + let mut b = app(); + b.apply_prefs(UiState::from_json(&serde_json::to_vec(&saved).unwrap()).unwrap()); + assert!(!b.session.view.proofing, "spelling stays off after a restart"); + } + /// Settings saved before #838 kept the unit under `editing.units` (default inches): a unit /// the user chose carries over to `measurementUnits`; inches, junk or a newer value don't. #[test]