From 4c318493a2dc3f1aaa8862b8a73167bee385873a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 20:01:14 -0800 Subject: [PATCH] Paragraph Style Options: Hyphenation Zone is disabled with an every-line composer Hyphenation Zone applies only with a single-line composer. The field now takes input only while Hyphenation is on and Composition is unset or a single-line composer. New Paragraph Style uses the same rows and gets the same rule. An invalid value left in a disabled Hyphenation option no longer blocks OK, and the style keeps that option's stored value. This covers Words Longer Than, After First, Before Last and Hyphen Limit after Hyphenation is turned off, as well as Hyphenation Zone. One check decides both whether a field takes input and whether its draft is set aside, so an enabled field with an invalid value still keeps the dialog open. --- .../ui-egui/src/dialogs/para_style_options.rs | 69 ++++++++++++++++-- .../src/dialogs/para_style_options/tests.rs | 70 ++++++++++++++++++- docs/mcp.md | 3 +- 3 files changed, 134 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/dialogs/para_style_options.rs b/crates/ui-egui/src/dialogs/para_style_options.rs index 609fca1dce..d8483e4543 100644 --- a/crates/ui-egui/src/dialogs/para_style_options.rs +++ b/crates/ui-egui/src/dialogs/para_style_options.rs @@ -42,6 +42,9 @@ const DISTANCES: [&str; 5] = ["left_indent", "right_indent", "first_line_indent" /// The range of the indents, the space before and after, and the Hyphenation Zone (pt), as /// `text.setFormat` keeps them. const MAX_DISTANCE: f64 = 1296.0; +/// The composers that take a Hyphenation Zone. With Composition unset, the style follows the +/// paragraph's composer and the zone stays available. +const SINGLE_LINE_COMPOSERS: [&str; 2] = ["singleLine", "standardSingleLine"]; /// The whole-number fields of Hyphenation: (field, `hyphenation` key, range). const COUNTS: [(&str, &str, (f64, f64)); 4] = [ ("words_longer_than", "words_longer_than", (1.0, 25.0)), @@ -309,6 +312,28 @@ pub(crate) fn edited_attrs(fields: &DialogFields, opening: &Opening) -> Result = HYPHENATION_FIELDS + .into_iter() + .filter(|key| !field_enabled(&d, key) && d.get(key) != original_fields.get(*key) && !valid(&d, key, unit)) + .collect(); + let normalized; + let d = if blocked.is_empty() { + d + } else { + let mut kept = fields.clone(); + for key in blocked { + match original_fields.get(key).and_then(Value::as_str).filter(|_| !d.reset("hyphenation")) { + Some(stored) => kept.set(key, stored), + None => { + kept.remove(key); + } + } + } + normalized = kept; + Values::new(&normalized) + }; let mut attrs = original.clone(); let unchanged = |key: &str, tab: &str| !d.reset(tab) && d.get(key) == original_fields.get(key); let keep_or = |attrs: &mut Map, key: &str, unchanged: bool, value: Option| { @@ -678,13 +703,45 @@ fn composition_rows() -> Vec { rows(vec![select("composer", tl!("Composition"), &composers), tri_state("roman_hanging", tl!("Roman Hanging Punctuation"))]) } -// PLAN: Hyphenation Zone is gated on Hyphenation alone; the Single-line Composer condition needs a gate on two keys. -fn hyphenation_rows() -> Vec { +/// Whether Hyphenation Zone needs Composition unset or a single-line composer to take input. +fn needs_single_line(key: &str) -> bool { + key == "hyphenation_zone" +} + +/// Whether field `key` takes input: the Hyphenation options while Hyphenation is on, and +/// Hyphenation Zone only while Composition is also unset or a single-line composer. Every other +/// field takes input. +fn field_enabled(d: &Values, key: &str) -> bool { + if !HYPHENATION_FIELDS.contains(&key) { + return true; + } + d.get("hyphenate").and_then(Value::as_bool) == Some(true) + && (!needs_single_line(key) + || d.get("composer").and_then(Value::as_str).is_none_or(|composer| composer.is_empty() || SINGLE_LINE_COMPOSERS.contains(&composer))) +} + +/// Whether the text of Hyphenation field `key` is a value the field accepts. +fn valid(d: &Values, key: &str, unit: Unit) -> bool { + match COUNTS.iter().find(|(field, _, _)| *field == key) { + Some((field, _, (lo, hi))) => count(d, field, *lo, *hi).is_ok(), + None if key == "hyphenation_zone" => distance(d, key, unit, 0.0, MAX_DISTANCE).is_ok(), + None => true, + } +} + +/// The Hyphenation options take input as [`field_enabled`] says: Hyphenation Zone applies only +/// with a single-line composer, so it is disabled while Composition holds another one. +fn hyphenation_rows(fields: &DialogFields) -> Vec { let on = FieldValue::Bool(true); + let composer_set = fields.text("composer").is_some_and(|composer| !composer.is_empty()); + let gate = |key: &str, param: Param| { + let param = param.enabled_when("hyphenate", on.clone()); + if needs_single_line(key) && composer_set { param.and_enabled_when_in("composer", SINGLE_LINE_COMPOSERS) } else { param } + }; let mut params = vec![tri_state("hyphenate", tl!("Hyphenation"))]; - params.extend(COUNTS.iter().map(|(key, _, _)| text(*key, label_of(key)).enabled_when("hyphenate", on.clone()))); - params.push(text("hyphenation_zone", label_of("hyphenation_zone")).enabled_when("hyphenate", on.clone())); - params.push(tri_state("hyphenate_capitalized", tl!("Hyphenate Capitalized Words")).enabled_when("hyphenate", on)); + params.extend(COUNTS.iter().map(|(key, _, _)| gate(key, text(*key, label_of(key))))); + params.push(gate("hyphenation_zone", text("hyphenation_zone", label_of("hyphenation_zone")))); + params.push(gate("hyphenate_capitalized", tri_state("hyphenate_capitalized", tl!("Hyphenate Capitalized Words")))); rows(params) } @@ -737,7 +794,7 @@ pub(crate) fn tabs(fields: &DialogFields, opening: &Opening) -> Vec