diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs
index 345e1ff995..1f0c290191 100644
--- a/crates/mcp/src/ui_catalog.rs
+++ b/crates/mcp/src/ui_catalog.rs
@@ -1591,7 +1591,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.hyphenation",
"Hyphenation…",
"",
- "{} open Hyphenation (the Paragraph panel menu's Hyphenation…) on the paragraphs the Paragraph panel acts on, filled in with the values it shows (dialog `hyphenation`: hyphenate, wordsLongerThan 1..25, afterFirst 1..15, beforeLast 1..15, hyphenLimit 0..25 (0: no limit), hyphenationZone (pt), hyphenateCapitalized): OK runs text.setFormat with the values that changed, as one undo step; an error with no type selected",
+ "{} open Hyphenation (the Paragraph panel menu's Hyphenation…) on the paragraphs the Paragraph panel acts on, filled in with the values it shows (dialog `hyphenation`: hyphenate, wordsLongerThan 1..25, afterFirst 1..15, beforeLast 1..15, hyphenLimit 0..25 (0: no limit), hyphenationZone (pt), hyphenateCapitalized; the fields after hyphenate take input only while it is true, and hyphenationZone, which only a single-line composer uses, never while every paragraph uses another composer): OK runs text.setFormat with the values that changed, as one undo step; an error with no type selected",
),
(
"ui.tateChuYokoSettings",
diff --git a/crates/ui-egui/src/dialogs/hyphenation.rs b/crates/ui-egui/src/dialogs/hyphenation.rs
index 4e9fae0914..d6767ba3bc 100644
--- a/crates/ui-egui/src/dialogs/hyphenation.rs
+++ b/crates/ui-egui/src/dialogs/hyphenation.rs
@@ -3,14 +3,16 @@
//! Longer Than, After First, Before Last, Hyphen Limit, Hyphenation Zone and Hyphenate Capitalized
//! Words. The dialog opens on the values the Paragraph panel shows (blank fields and dashed
//! checkboxes where paragraphs in scope disagree). OK runs `text.setFormat` with the values that
-//! changed, as one undo step, and paragraphs that differ keep the values left alone.
+//! changed, as one undo step, and paragraphs that differ keep the values left alone. The options
+//! below the checkbox take input only while Hyphenation is on, and Hyphenation Zone, which applies
+//! only to a single-line composer, is disabled when every paragraph in scope uses another composer.
//!
//! Fields: `hyphenate`, `wordsLongerThan` (letters, 1..25), `afterFirst` and `beforeLast`
//! (letters, 1..15), `hyphenLimit` (hyphens, 0..25, 0: no limit), `hyphenationZone` (pt) and
//! `hyphenateCapitalized`, as `text.setFormat` takes them.
use craft::ui::contract::Bind;
-use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, Param, ParamDialog, ParamKind};
+use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind};
// PLAN: assumed paths of `UnitKind` and `LengthUnits`
use craft::ui::runtime::env::{LengthUnits, UnitKind};
use serde_json::{Map, Value, json};
@@ -27,18 +29,21 @@ const FLAGS: [&str; 2] = ["hyphenate", "hyphenateCapitalized"];
const NUMBERS: [(&str, i64, i64); 5] =
[("wordsLongerThan", 1, 25), ("afterFirst", 1, 15), ("beforeLast", 1, 15), ("hyphenLimit", 0, 25), ("hyphenationZone", 0, 0)];
-/// The rows of the dialog; the zone is shown in `lengths`.
-fn rows(lengths: LengthUnits) -> Vec {
+/// The rows of the dialog; the zone is shown in `lengths`. Every row below the checkbox takes input
+/// only while Hyphenation is on, and Hyphenation Zone is disabled when `zone` is false.
+fn rows(lengths: LengthUnits, zone: bool) -> Vec {
+ let on = |param: Param| param.enabled_when(FLAGS[0], FieldValue::Bool(true));
let count =
- |(key, lo, hi): (&str, i64, i64), label, default, unit| Param::new(key, label, ParamKind::int(Some(lo), Some(hi), default)).unit(unit);
+ |(key, lo, hi): (&str, i64, i64), label, default, unit| on(Param::new(key, label, ParamKind::int(Some(lo), Some(hi), default)).unit(unit));
+ let zone_row = on(Param::number(NUMBERS[4].0, tl!("Hyphenation Zone:"), 0.0, 1.0, 2).length(lengths).bounds(Some(0.0), None));
vec![
Param::new(FLAGS[0], tl!("Hyphenation"), ParamKind::bool(false)),
count(NUMBERS[0], tl!("Words Longer Than:"), 5, UnitKind::Letters),
count(NUMBERS[1], tl!("After First:"), 3, UnitKind::Letters),
count(NUMBERS[2], tl!("Before Last:"), 3, UnitKind::Letters),
count(NUMBERS[3], tl!("Hyphen Limit:"), 0, UnitKind::Hyphens),
- Param::number(NUMBERS[4].0, tl!("Hyphenation Zone:"), 0.0, 1.0, 2).length(lengths).bounds(Some(0.0), None),
- Param::new(FLAGS[1], tl!("Hyphenate Capitalized Words"), ParamKind::bool(true)),
+ if zone { zone_row } else { zone_row.disabled() },
+ on(Param::new(FLAGS[1], tl!("Hyphenate Capitalized Words"), ParamKind::bool(true))),
]
}
@@ -76,11 +81,12 @@ pub fn open(app: &mut VectorcraftApp) -> Result {
set_shared(&mut fields, NUMBERS[2].0, crate::panels::paragraph::shared_hyphenation_field(app, |h| h.before_last).map(i64::from));
set_shared(&mut fields, NUMBERS[3].0, crate::panels::paragraph::shared_hyphenation_field(app, |h| h.hyphen_limit).map(i64::from));
set_shared(&mut fields, NUMBERS[4].0, crate::panels::paragraph::shared_hyphenation_zone(app));
+ let zone = crate::panels::paragraph::shared_para(app, |p| p.composer.is_single_line()) != Some(false);
let initial = fields.clone();
let ctx = app.ui_ctx.clone().ok_or("no window")?;
let lengths = crate::canvas::rulers::general_lengths(app);
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |fields| {
- ParamDialog::new(KIND, tl!("Hyphenation"), rows(lengths)).values(Bind::bound(fields))
+ ParamDialog::new(KIND, tl!("Hyphenation"), rows(lengths, zone)).values(Bind::bound(fields))
});
super::host::open_held(app, dialog, move |app, result| {
let mut p = params(&result.fields, &initial);
@@ -221,27 +227,40 @@ mod tests {
let modal = control(&tree, "Hyphenation", Role::Dialog, None);
let count = control(&tree, "Words Longer Than:", Role::SpinButton, Some(modal));
let enabled = control(&tree, "Hyphenation", Role::CheckBox, Some(modal));
+ let capitalized = control(&tree, "Hyphenate Capitalized Words", Role::CheckBox, Some(modal));
let footer = control(&tree, if apply { "OK" } else { "Cancel" }, Role::Button, Some(modal));
assert!(screen.expand(0.5).contains_rect(modal));
- for bounds in [count, enabled, footer] {
+ for bounds in [count, enabled, capitalized, footer] {
assert!(bounds.is_positive() && modal.expand(0.5).contains_rect(bounds), "{lang}: {bounds:?} outside {modal:?}");
}
let before = driver::fields(&app);
assert_eq!(before.number("wordsLongerThan"), Some(5.0));
assert_eq!(before.bool("hyphenate"), Some(false));
assert!(before.is_mixed("afterFirst"));
+ assert_eq!(before.bool("hyphenateCapitalized"), Some(true));
+ // The counts take input once Hyphenation is on.
+ click(&mut app, &mut frame, enabled.center());
+ settle(&mut app, &mut frame);
+ let checked = draft(&app, &ctx)["hyphenate"].as_bool();
click(&mut app, &mut frame, count.center());
press(&mut app, &mut frame, Key::A, Modifiers::COMMAND);
frame(&mut app, vec![Event::ModifiersChanged(Modifiers::NONE), Event::Text("8".into())]);
press(&mut app, &mut frame, Key::Tab, Modifiers::NONE);
settle(&mut app, &mut frame);
- let typed = draft(&app, &ctx)["wordsLongerThan"].as_f64();
- click(&mut app, &mut frame, enabled.center());
let inspected = draft(&app, &ctx);
let kept = (inspected["wordsLongerThan"].as_f64(), inspected["hyphenate"].as_bool());
- eprintln!("{lang}, {answer}: {modal:?}; ui.inspect after typing {typed:?}, after checkbox {kept:?}");
- if typed != Some(8.0) || kept != (Some(8.0), Some(true)) || !driver::fields(&app).is_mixed("afterFirst") {
- failures.push(format!("{lang} {answer}: {typed:?}, {kept:?}"));
+ eprintln!("{lang}, {answer}: {modal:?}; ui.inspect after checkbox {checked:?}, after typing {kept:?}");
+ if checked != Some(true) || kept != (Some(8.0), Some(true)) || !driver::fields(&app).is_mixed("afterFirst") {
+ failures.push(format!("{lang} {answer}: {checked:?}, {kept:?}"));
+ }
+ // Clicking another option after typing keeps the typed count.
+ click(&mut app, &mut frame, capitalized.center());
+ settle(&mut app, &mut frame);
+ let inspected = draft(&app, &ctx);
+ let other = (inspected["wordsLongerThan"].as_f64(), inspected["hyphenateCapitalized"].as_bool());
+ eprintln!("{lang}, {answer}: ui.inspect after the second checkbox {other:?}");
+ if other != (Some(8.0), Some(false)) {
+ failures.push(format!("{lang} {answer}: after the second checkbox {other:?}"));
}
assert_eq!(paras(&app, id), original, "{lang}: only the draft changes while open");
if answer == "ui.dialog.confirm" {
@@ -271,6 +290,7 @@ mod tests {
for p in [&mut expected.0, &mut expected.1] {
p.hyphenation.words_longer_than = 8;
p.hyphenate = true;
+ p.hyphenation.capitalized = false;
}
if actual != expected || undo_delta != 1 {
failures.push(format!(
@@ -293,6 +313,7 @@ mod tests {
#[test]
fn hyphenation_dialog_sets_the_paragraphs_options() {
let (mut app, id) = app();
+ app.run("text.setFormat", json!({"ids": [id], "composer": "singleLine"})).unwrap();
app.run("ui.hyphenation", json!({})).unwrap();
let f = driver::fields(&app);
assert_eq!((f.bool("hyphenate"), f.number("wordsLongerThan"), f.number("hyphenLimit")), (Some(false), Some(5.0), Some(0.0)));
@@ -322,6 +343,7 @@ mod tests {
app.run("text.setFormat", json!({"ids": [id], "afterFirst": 2, "start": 5, "end": 5})).unwrap();
app.run("ui.hyphenation", json!({})).unwrap();
assert!(driver::fields(&app).is_mixed("afterFirst"));
+ driver::set(&mut app, "hyphenate", json!(true));
driver::set(&mut app, "beforeLast", json!(4));
driver::ok(&mut app);
let (first, second) = paras(&app, id);
@@ -337,6 +359,82 @@ mod tests {
assert!(!driver::is_open(&app));
}
+ /// The options below the checkbox take input only while Hyphenation is on, on screen and through
+ /// automation, including while the paragraphs in scope disagree on Hyphenation.
+ #[test]
+ fn hyphenation_options_take_input_only_with_hyphenation_on() {
+ let options = [
+ ("Words Longer Than", "wordsLongerThan", json!(8)),
+ ("After First", "afterFirst", json!(2)),
+ ("Before Last", "beforeLast", json!(4)),
+ ("Hyphen Limit", "hyphenLimit", json!(2)),
+ ("Hyphenation Zone", "hyphenationZone", json!(12)),
+ ("Hyphenate Capitalized Words", "hyphenateCapitalized", json!(false)),
+ ];
+ for mixed in [false, true] {
+ let (mut app, id) = app();
+ app.run("text.setFormat", json!({"ids": [id], "composer": "singleLine"})).unwrap();
+ if mixed {
+ app.run("text.setFormat", json!({"ids": [id], "hyphenate": true, "start": 5, "end": 5})).unwrap();
+ }
+ let mut panel = crate::tests::panel_harness::Panel::new(app, crate::tests::picks::dialogs);
+ panel.app().run("ui.hyphenation", json!({})).unwrap();
+ panel.frame();
+ assert_eq!(driver::fields(&panel.app()).is_mixed("hyphenate"), mixed);
+ for (label, key, value) in &options {
+ assert!(!panel.enabled(label), "mixed {mixed}: {label} takes input with Hyphenation off");
+ assert!(driver::try_set(&mut panel.app(), key, value.clone()).is_err(), "mixed {mixed}: automation set {key}");
+ }
+ driver::set(&mut panel.app(), "hyphenate", json!(true));
+ panel.frame();
+ for (label, key, value) in &options {
+ assert!(panel.enabled(label), "mixed {mixed}: {label} is disabled with Hyphenation on");
+ driver::try_set(&mut panel.app(), key, value.clone()).unwrap_or_else(|e| panic!("mixed {mixed}: {key} refused: {e}"));
+ }
+ driver::ok(&mut panel.app());
+ let want = HyphenationOptions { words_longer_than: 8, after_first: 2, before_last: 4, hyphen_limit: 2, zone: 12.0, capitalized: false };
+ let (first, second) = paras(&panel.app(), id);
+ for p in [first, second] {
+ assert!(p.hyphenate && p.hyphenation == want, "mixed {mixed}: {p:?}");
+ }
+ }
+ }
+
+ /// Hyphenation Zone applies only to a single-line composer: it is disabled while every paragraph
+ /// in scope uses another composer, and takes input when any of them uses a single-line one. The
+ /// other options stay available either way.
+ #[test]
+ fn hyphenation_zone_takes_input_only_with_a_single_line_composer() {
+ let cases = [
+ (["everyLine", "everyLine"], false),
+ (["standardEveryLine", "everyLine"], false),
+ (["singleLine", "singleLine"], true),
+ (["standardSingleLine", "standardSingleLine"], true),
+ (["everyLine", "standardSingleLine"], true),
+ ];
+ for (composers, zone) in cases {
+ let (mut app, id) = app();
+ app.run("text.setFormat", json!({"ids": [id], "hyphenate": true})).unwrap();
+ for (at, composer) in [0, 5].into_iter().zip(composers) {
+ app.run("text.setFormat", json!({"ids": [id], "composer": composer, "start": at, "end": at})).unwrap();
+ }
+ let mut panel = crate::tests::panel_harness::Panel::new(app, crate::tests::picks::dialogs);
+ panel.app().run("ui.hyphenation", json!({})).unwrap();
+ panel.frame();
+ assert_eq!(panel.enabled("Hyphenation Zone"), zone, "{composers:?}: Hyphenation Zone on screen");
+ assert!(panel.enabled("Words Longer Than"), "{composers:?}");
+ let set = driver::try_set(&mut panel.app(), "hyphenationZone", json!(36));
+ assert_eq!(set.is_ok(), zone, "{composers:?}: automation set the zone: {set:?}");
+ driver::set(&mut panel.app(), "wordsLongerThan", json!(7));
+ driver::ok(&mut panel.app());
+ let want = if zone { 36.0 } else { 0.0 };
+ let (first, second) = paras(&panel.app(), id);
+ for p in [first, second] {
+ assert_eq!((p.hyphenation.zone, p.hyphenation.words_longer_than), (want, 7), "{composers:?}");
+ }
+ }
+ }
+
#[test]
fn hyphenation_confirm_keeps_the_opening_selection() {
let (mut app, first) = app();
diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs
index 61edc5a5c4..f783fd4464 100644
--- a/crates/ui-egui/src/menus/ui_commands.rs
+++ b/crates/ui-egui/src/menus/ui_commands.rs
@@ -1592,7 +1592,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.hyphenation",
"Hyphenation…",
"",
- "{} open Hyphenation (the Paragraph panel menu's Hyphenation…) on the paragraphs the Paragraph panel acts on, filled in with the values it shows (dialog `hyphenation`: hyphenate, wordsLongerThan 1..25, afterFirst 1..15, beforeLast 1..15, hyphenLimit 0..25 (0: no limit), hyphenationZone (pt), hyphenateCapitalized): OK runs text.setFormat with the values that changed, as one undo step; an error with no type selected",
+ "{} open Hyphenation (the Paragraph panel menu's Hyphenation…) on the paragraphs the Paragraph panel acts on, filled in with the values it shows (dialog `hyphenation`: hyphenate, wordsLongerThan 1..25, afterFirst 1..15, beforeLast 1..15, hyphenLimit 0..25 (0: no limit), hyphenationZone (pt), hyphenateCapitalized; the fields after hyphenate take input only while it is true, and hyphenationZone, which only a single-line composer uses, never while every paragraph uses another composer): OK runs text.setFormat with the values that changed, as one undo step; an error with no type selected",
),
(
"ui.tateChuYokoSettings",
diff --git a/docs/mcp.md b/docs/mcp.md
index 066dc4dbb5..4b5ea6383f 100644
--- a/docs/mcp.md
+++ b/docs/mcp.md
@@ -14358,10 +14358,11 @@ The letter and line counts are rounded, and every value is clamped to its range.
listed word. The options are saved with the paragraph (`hyphenation` in `para`) only when they differ from the
defaults, and paragraph styles carry them (`paraStyle.new {attrs: {hyphenation: {words_longer_than: 8}}}`). One undo
step. `ui.hyphenation` opens the Hyphenation dialog on the values the Paragraph panel shows; OK sends the values that
-changed. The UI command `type.hyphenate` (Cmd+Alt+Shift+H, in remote mode `press_key {key: "H", mods: {cmd: true,
-alt: true, shift: true}}` or `invoke_menu`) does what the Hyphenate checkbox does: it turns `hyphenate` off when
-every paragraph of the selected type (or every paragraph the Type tool's selection touches) hyphenates, else on, and
-returns the new value.
+changed. The options below the Hyphenation checkbox take input only while it is checked, and Hyphenation Zone is
+disabled while no paragraph in scope uses a single-line composer. The UI command `type.hyphenate` (Cmd+Alt+Shift+H,
+in remote mode `press_key {key: "H", mods: {cmd: true, alt: true, shift: true}}` or `invoke_menu`) does what the
+Hyphenate checkbox does: it turns `hyphenate` off when every paragraph of the selected type (or every paragraph the
+Type tool's selection touches) hyphenates, else on, and returns the new value.
```json
{"name":"run_command","arguments":{"command":"text.setFormat","params":{"hyphenate":true,"wordsLongerThan":8,"hyphenLimit":2}}}