diff --git a/crates/engine/src/cmd/format/paragraph.rs b/crates/engine/src/cmd/format/paragraph.rs index e4b02a4b9..64bb16487 100644 --- a/crates/engine/src/cmd/format/paragraph.rs +++ b/crates/engine/src/cmd/format/paragraph.rs @@ -120,13 +120,7 @@ pub(super) fn line_spacing(s: &mut Session, p: &Value) -> Result { } pub(super) fn paragraph(s: &mut Session, p: &Value) -> Result { - let a = str_param(p, "align").map(|a| match a { - "center" => Align::Center, - "right" => Align::Right, - "justify" => Align::Justify, - "distributed" => Align::Distributed, - _ => Align::Left, - }); + let a = str_param(p, "align").map(|a| parse_align("format.paragraph", a)).transpose()?; let ml = f64_param(p, "indentLeft"); let ind = f64_param(p, "indentFirst"); let sb = f64_param(p, "spaceBefore"); @@ -182,10 +176,10 @@ pub(super) fn clamp_pt(v: f64) -> f64 { fn parse_align(cmd: &str, s: &str) -> Result { Ok(match s { "left" | "l" => Align::Left, - "center" | "ctr" => Align::Center, + "center" | "centre" | "ctr" => Align::Center, "right" | "r" => Align::Right, "justify" | "just" => Align::Justify, - "justLow" => Align::JustLow, + "justLow" | "justifyLow" => Align::JustLow, "distributed" | "dist" => Align::Distributed, "thaiDist" => Align::ThaiDistributed, _ => return Err(bad(cmd, "`align` must be left, center, right, justify, justLow, distributed or thaiDist")), diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 7d55a9b16..5d2310328 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -1713,6 +1713,31 @@ fn tab_moves_between_cells_skipping_merged_ones() { assert_eq!((cell(&s), table_of(&s, id).n_rows()), (Some((2, 0)), 3), "Tab in the last cell adds a row"); } +#[test] +fn format_paragraph_align_names_match_format_align() { + use deckcraft_model::text::Align; + let mut s = session(); + let title = s.doc().unwrap().current_slide().unwrap().shapes[0].id.0; + s.execute("text.edit", &json!({"id": title})).unwrap(); + let para = |s: &Session| s.doc().unwrap().current_slide().unwrap().shapes[0].text.as_ref().unwrap().paragraphs[0].props.align; + for (name, want) in [ + ("justLow", Align::JustLow), + ("justifyLow", Align::JustLow), + ("thaiDist", Align::ThaiDistributed), + ("ctr", Align::Center), + ("centre", Align::Center), + ("r", Align::Right), + ("just", Align::Justify), + ("dist", Align::Distributed), + ("distributed", Align::Distributed), + ("left", Align::Left), + ] { + s.execute("format.paragraph", &json!({"align": name})).unwrap(); + assert_eq!(para(&s), Some(want), "{name}"); + } + assert!(s.execute("format.paragraph", &json!({"align": "bogus"})).is_err()); +} + #[test] fn right_to_left_paragraphs() { let mut s = session();