Type: a paragraph style refuses a custom Kinsoku set it would drop

A custom Kinsoku set goes with Hard and has a name a custom set can
have. paraStyle.new and paraStyle.setAttrs given a custom set together
with `kinsoku` None or Soft, or a set with a blank or built-in name,
reported success while the style kept no custom set. They now fail
with an error and leave the styles unchanged.
This commit is contained in:
dotCooCoo committed 2026-11-14 14:57:34 -08:00
1 parent bfdffe55a3
commit dc89f8d953
3 files changed
+41 -1

No files matched your search

@@ -186,6 +186,34 @@ fn a_styles_custom_set_is_one_of_the_documents() {
assert!(s.execute("paraStyle.setAttrs", &json!({"name": "Body", "attrs": {"kinsoku_set": {"name": "Missing"}}})).is_err());
}
/// A custom set goes with Hard and has a name a custom set can have: a paragraph style call that
/// gives one beside None or Soft, or with a blank or built-in name, fails and leaves the styles as
/// they were, and one beside Hard is kept.
#[test]
fn a_styles_custom_set_given_beside_none_or_soft_fails_the_call() {
let mut s = session();
s.execute("type.kinsokuSets.set", &json!({"sets": [tight()]})).unwrap();
s.execute("paraStyle.new", &json!({"name": "Body", "attrs": {"kinsoku_set": tight_set(&s)}})).unwrap();
let styles = |s: &Session| s.doc().unwrap().doc.para_styles.clone();
let before = styles(&s);
for kinsoku in ["none", "soft"] {
let attrs = json!({"kinsoku": kinsoku, "kinsoku_set": tight_set(&s)});
assert!(s.execute("paraStyle.new", &json!({"name": "Other", "attrs": attrs})).is_err(), "new with {kinsoku}");
assert!(s.execute("paraStyle.setAttrs", &json!({"name": "Body", "attrs": attrs})).is_err(), "setAttrs with {kinsoku}");
assert_eq!(styles(&s), before, "{kinsoku}");
}
for name in ["", " ", "Hard", "soft"] {
let attrs = json!({"kinsoku_set": {"name": name}});
assert!(s.execute("paraStyle.new", &json!({"name": "Other", "attrs": attrs})).is_err(), "new named `{name}`");
assert!(s.execute("paraStyle.setAttrs", &json!({"name": "Body", "attrs": attrs})).is_err(), "setAttrs named `{name}`");
assert_eq!(styles(&s), before, "`{name}`");
}
let attrs = json!({"kinsoku": "hard", "kinsoku_set": tight_set(&s)});
s.execute("paraStyle.new", &json!({"name": "Other", "attrs": attrs})).unwrap();
let other = styles(&s).into_iter().find(|st| st.name == "Other").unwrap();
assert_eq!(other.attrs["kinsoku_set"], tight_set(&s));
}
/// Editing a set gives every paragraph and paragraph style using it the new characters, renaming it
/// (`from`) the new name too, and deleting it sets them to Hard: each in one undo step, which undo
/// takes back with the set. Paragraphs using no set, or another set, stay as they are.
+11
View File
@@ -677,6 +677,17 @@ fn attrs_param(d: &Document, p: &Value, kind: Kind, verb: &str, kept: Option<&Ma
let mut st = with_attrs(&ParaStyle::default(), m, &c)?;
para_ranges(&st, m, kept, &c)?;
sort_tabs(&mut st, m, kept);
// A custom Kinsoku set goes with Hard and has a name a custom set can have: one
// given beside None or Soft, or with a blank or built-in name, fails the call
// instead of being dropped.
if m.get("kinsoku_set").is_some_and(|v| !v.is_null()) && KINSOKU.iter().any(|k| kept.and_then(|kept| kept.get(*k)) != m.get(*k)) {
if st.kinsoku != vectorcraft_doc::Kinsoku::Hard {
return Err(bad(&c, "`kinsoku_set` goes with `kinsoku` Hard: give `kinsoku` as `hard` or leave it out"));
}
if st.kinsoku_set.is_none() {
return Err(bad(&c, "`kinsoku_set` needs the name of one of the document's Kinsoku sets"));
}
}
// A custom Kinsoku set is one of the document's, by name (any case), as
// `text.setFormat` chooses it; one the style already holds stays.
if let Some(set) = &st.kinsoku_set
+2 -1
View File
@@ -8685,7 +8685,8 @@ JLREQ's level 3 line-breaking rules do (https://www.w3.org/TR/jlreq/#addendum_a3
**None** applies no kinsoku. `hard` isn't saved. The name of a custom set of the document (`type.kinsokuSets.list`, any
case) gives each paragraph a copy of that set, saved with the paragraph (`kinsoku_set` in `para`) beside Hard, so an
older build reads the paragraph as Hard; a name the document has no set of fails the call and changes nothing.
Paragraph styles carry the set. One undo step.
Paragraph styles carry the set; `paraStyle.new` and `paraStyle.setAttrs` given `kinsoku_set` with `kinsoku` None or Soft,
or with a blank or built-in set name, fail and change nothing. One undo step.
```json
{"name":"run_command","arguments":{"command":"text.setFormat","params":{"kinsoku":"soft"}}}