mirror of
https://github.com/storytold/wordcraft.git
synced 2026-10-28 04:17:06 -06:00
engine: Check spelling as you type is saved with the proofing options, so it survives a restart
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -104,6 +104,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
.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(),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user