mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-17 05:24:43 +00:00
#3518: whole-document language keeps per-run proofing, returns selection, skips glossary while tracking
- Language dialog: whole-document OK sends noProof only when the box was changed, so a language-only change no longer marks everything no-proof. - review.language scope "document" returns the caret/selection result (plus scope). - Whole-document change skips glossary blocks while Track Changes and Track Formatting are on (tracked formatting does not cover them). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
36a899eccf
commit
5fbf8b0252
@@ -67,7 +67,12 @@ pub(super) fn language(s: &mut Session, v: &Value) -> CmdResult {
|
||||
};
|
||||
let result = if whole_document {
|
||||
set_document_props(s, &change)?;
|
||||
json!({"scope": "document"})
|
||||
// The same caret/selection result as the selection path (the selection is untouched).
|
||||
let mut r = sel_result(s)?;
|
||||
if let Some(m) = r.as_object_mut() {
|
||||
m.insert("scope".into(), json!("document"));
|
||||
}
|
||||
r
|
||||
} else {
|
||||
crate::cmd::format::apply(s, &change)?
|
||||
};
|
||||
@@ -81,6 +86,10 @@ pub(super) fn language(s: &mut Session, v: &Value) -> CmdResult {
|
||||
/// to the whole document"): text and paragraph marks of the body, headers, footers, notes,
|
||||
/// comments, text boxes (all `Document::parts`), table cells, and the glossary's building blocks.
|
||||
/// The selection is untouched; formatting waiting for typing follows.
|
||||
///
|
||||
/// Glossary blocks are left alone while Track Changes and Track Formatting are both on: tracked
|
||||
/// formatting (`fmt_revisions::record`) compares only the body and the parts, so a glossary change
|
||||
/// would be an untracked edit. Like every other command, tracked edits never reach the glossary.
|
||||
fn set_document_props(s: &mut Session, f: &dyn Fn(&mut CharProps)) -> Result<(), CmdError> {
|
||||
let stories: Vec<StoryRef> = std::iter::once(StoryRef::Body).chain(s.doc.parts.keys().map(|k| StoryRef::Part(*k))).collect();
|
||||
for story in stories {
|
||||
@@ -92,8 +101,10 @@ fn set_document_props(s: &mut Session, f: &dyn Fn(&mut CharProps)) -> Result<(),
|
||||
para.touch();
|
||||
}
|
||||
}
|
||||
for block in &mut s.doc.glossary {
|
||||
format_blocks(&mut block.blocks, f, 0);
|
||||
if !(s.doc.settings.track_changes && s.prefs.markup.track_formatting) {
|
||||
for block in &mut s.doc.glossary {
|
||||
format_blocks(&mut block.blocks, f, 0);
|
||||
}
|
||||
}
|
||||
if let Some(pend) = s.pending.as_mut() {
|
||||
f(pend);
|
||||
|
||||
@@ -340,7 +340,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
})
|
||||
.params(r#"{"format": "decimal|upperRoman|lowerLetter…", "text"?: "%1.", "start"?: n}"#),
|
||||
CommandSpec::new("review.language", "Language", "Review › Language", language).params(
|
||||
r#"{"lang"?: "en-US|en-GB|pl-PL|fr-FR|…" (BCP 47; default en-US), "noProof"?: bool, "detect"?: bool (detect language automatically, a preference), "default"?: bool (also the document's default and the saved language for future blank documents), "scope"?: "selection" (default) | "document" (every run and paragraph mark of every story: body, headers, footers, notes, comments, text boxes, tables, glossary; one undo step, selection unchanged)}"#,
|
||||
r#"{"lang"?: "en-US|en-GB|pl-PL|fr-FR|…" (BCP 47; default en-US), "noProof"?: bool, "detect"?: bool (detect language automatically, a preference), "default"?: bool (also the document's default and the saved language for future blank documents), "scope"?: "selection" (default) | "document" (every run and paragraph mark of every story: body, headers, footers, notes, comments, text boxes, tables, glossary (skipped while Track Changes and Track Formatting are on); one undo step, selection unchanged; returns the caret and "scope":"document")}"#,
|
||||
),
|
||||
CommandSpec::new("review.language.preferred", "Set as Default Language", "File › Options › Language", preferred_language)
|
||||
.params(r#"{"lang": "en-US|en-GB|pl-PL|nl-NL|…" (BCP 47)} — only the saved default proofing language, what future blank documents are written in, as Options › Language › Set as default does; the open document, the selection and the undo history don't change. Returns {"preferred": tag}."#)
|
||||
|
||||
@@ -979,6 +979,36 @@ fn language_scope_document_no_proof_and_pending() {
|
||||
assert_eq!(s.pending.as_ref().and_then(|p| p.lang.as_deref()), Some("pl-PL"));
|
||||
}
|
||||
|
||||
/// Document scope returns the caret/selection like the selection path, plus the scope.
|
||||
#[test]
|
||||
fn language_scope_document_returns_the_selection_result() {
|
||||
let mut s = multi_story_doc();
|
||||
s.run("select.text", &json!({"text": "Guten"})).unwrap();
|
||||
let out = s.run("review.language", &json!({"lang": "fr-FR", "scope": "document"})).unwrap();
|
||||
assert_eq!(out["scope"], "document");
|
||||
assert_eq!(out["anchor"], crate::cmd::pos_json(&s.sel.anchor), "{out}");
|
||||
assert_eq!(out["focus"], crate::cmd::pos_json(&s.sel.focus), "{out}");
|
||||
}
|
||||
|
||||
/// Tracked formatting records only the body and parts, so while it is on the glossary (outside
|
||||
/// any story) is left alone instead of changing untracked; with tracking off it changes.
|
||||
#[test]
|
||||
fn language_scope_document_skips_glossary_while_tracking_formatting() {
|
||||
let gloss = |s: &Session| s.doc.glossary[0].blocks[0].as_para().map(|p| (p.runs[0].props.lang.clone(), p.mark.lang.clone()));
|
||||
let mut s = multi_story_doc();
|
||||
s.run("review.trackChanges", &json!({"value": true})).unwrap();
|
||||
s.run("review.trackingOptions", &json!({"trackFormatting": true})).unwrap();
|
||||
s.run("review.language", &json!({"lang": "fr-FR", "scope": "document"})).unwrap();
|
||||
assert_eq!(gloss(&s), Some((Some("de-DE".into()), Some("de-DE".into()))));
|
||||
assert!(proofing_rows(&s).iter().all(|r| r.1.as_deref() == Some("fr-FR")));
|
||||
assert!(s.doc.revisions.iter().any(|r| r.kind == wordcraft_doc::RevisionKind::Format), "the body change is tracked");
|
||||
let mut s = multi_story_doc();
|
||||
s.run("review.trackChanges", &json!({"value": true})).unwrap();
|
||||
s.run("review.trackingOptions", &json!({"trackFormatting": false})).unwrap();
|
||||
s.run("review.language", &json!({"lang": "fr-FR", "scope": "document"})).unwrap();
|
||||
assert_eq!(gloss(&s), Some((Some("fr-FR".into()), Some("fr-FR".into()))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn language_default_scope_is_selection_only() {
|
||||
let mut s = multi_story_doc();
|
||||
|
||||
@@ -328,19 +328,21 @@ fn language_dialog_whole_document_sends_only_changes() {
|
||||
assert_eq!(f.params()["noProof"], false);
|
||||
}
|
||||
|
||||
/// #3518: a ticked Do-not-check box on a whole-document apply marks the whole document, even
|
||||
/// when the caret's text already had it (so the box is unchanged).
|
||||
/// #3518: a ticked Do-not-check box the user did not change (the caret sits in a no-proof run)
|
||||
/// is not sent, so a language-only whole-document apply leaves other runs' proofing state alone.
|
||||
#[test]
|
||||
fn language_dialog_whole_document_ticked_unchanged_no_proof_is_sent() {
|
||||
fn language_dialog_whole_document_unchanged_no_proof_is_not_sent() {
|
||||
let mut a = proofing_mix_app();
|
||||
a.run("select.text", json!({"text": "code"})).unwrap();
|
||||
let mut f = LanguageForm::read(&a);
|
||||
assert!(f.no_proof && f.initial.1);
|
||||
f.whole_document = true;
|
||||
f.lang = "en-GB".into();
|
||||
let p = f.params();
|
||||
assert_eq!(p["noProof"], true);
|
||||
assert!(p.get("noProof").is_none(), "{p}");
|
||||
a.run("review.language", p).unwrap();
|
||||
assert_eq!(run_proofing(&mut a, "Plain"), (Some("de-DE".into()), Some(true)));
|
||||
assert_eq!(run_proofing(&mut a, "code"), (Some("en-GB".into()), Some(true)));
|
||||
assert_eq!(run_proofing(&mut a, "Plain"), (Some("en-GB".into()), Some(false)));
|
||||
}
|
||||
|
||||
/// #407: Envelopes starts from the selected address; Add to Document puts an envelope
|
||||
|
||||
@@ -349,9 +349,9 @@ impl LanguageForm {
|
||||
if lang_changed || !proof_changed {
|
||||
m.insert("lang".into(), json!(self.lang));
|
||||
}
|
||||
// A ticked box means "don't check the whole document", changed or not; an unticked,
|
||||
// unchanged box is omitted so it doesn't clear runs that differ elsewhere.
|
||||
if proof_changed || self.no_proof {
|
||||
// Only a changed box is sent: the caret's value (ticked or not) says nothing about
|
||||
// runs that differ elsewhere, and resending it would flatten them.
|
||||
if proof_changed {
|
||||
m.insert("noProof".into(), json!(self.no_proof));
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user