From f0c1b4ff290d15d259b2a61c2eb8ddfdca641e6b Mon Sep 17 00:00:00 2001 From: SBaksa Date: Sat, 31 Oct 2026 14:20:48 +1100 Subject: [PATCH] -ATTDEF: the Justify prompt leaves out Align and Fit, which it refuses; TEXT keeps them (#1720) -ATTDEF can't take Align or Fit (they need two points), but its Justify prompt listed them because it shared TEXT's prompt. justify_prompt now filters them out of the one shared option list for -ATTDEF; typed A or F is still refused. Test: attdef_justify_prompt_leaves_out_align_and_fit_but_text_keeps_them. --- crates/engine/src/cmd/blocks.rs | 2 +- crates/engine/src/cmd/draw/text.rs | 14 ++++++---- crates/engine/tests/attdef_justify_style.rs | 29 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/blocks.rs b/crates/engine/src/cmd/blocks.rs index 0a88845d9..039753623 100644 --- a/crates/engine/src/cmd/blocks.rs +++ b/crates/engine/src/cmd/blocks.rs @@ -939,7 +939,7 @@ impl Interactive for AttdefM { } fn prompt(&self, s: &Session) -> Prompt { match self.asking { - Some(AttdefAsk::Justify) => return super::draw::justify_prompt(), + Some(AttdefAsk::Justify) => return super::draw::justify_prompt(false), Some(AttdefAsk::Style) => return Prompt::new("Enter style name", Accept::TEXT).default(current_text_style(s)), None => {} } diff --git a/crates/engine/src/cmd/draw/text.rs b/crates/engine/src/cmd/draw/text.rs index 2c190c84e..24007bc91 100644 --- a/crates/engine/src/cmd/draw/text.rs +++ b/crates/engine/src/cmd/draw/text.rs @@ -25,10 +25,14 @@ pub(crate) fn justify(j: &str) -> Option<(HAlign, VAlign)> { }) } -/// The prompt for a justification option (TEXT's `Justify`, `-ATTDEF`'s `Justify`). -pub(crate) fn justify_prompt() -> Prompt { - Prompt::new("Enter an option", Accept::TEXT) - .kw(&["Left", "Center", "Right", "Align", "Middle", "Fit", "TL", "TC", "TR", "ML", "MC", "MR", "BL", "BC", "BR"]) +/// The justification options TEXT offers, in prompt order. +const JUSTIFY_OPTIONS: [&str; 15] = ["Left", "Center", "Right", "Align", "Middle", "Fit", "TL", "TC", "TR", "ML", "MC", "MR", "BL", "BC", "BR"]; + +/// The prompt for a justification option. Align and Fit run between two baseline points, so a +/// command that takes one point (`-ATTDEF`) passes `two_points: false` and doesn't list them. +pub(crate) fn justify_prompt(two_points: bool) -> Prompt { + let options: Vec<&str> = JUSTIFY_OPTIONS.into_iter().filter(|o| two_points || !matches!(*o, "Align" | "Fit")).collect(); + Prompt::new("Enter an option", Accept::TEXT).kw(&options) } pub(crate) fn make_text(s: &Session, at: Vec2, value: &str, height: f64, rotation: f64, j: (HAlign, VAlign)) -> EntityKind { @@ -125,7 +129,7 @@ impl Interactive for TextM { fn prompt(&self, s: &Session) -> Prompt { let th = s.doc().map(|d| d.header.f64("TEXTSIZE", 0.2)).unwrap_or(0.2); if self.asking_justify { - return justify_prompt(); + return justify_prompt(true); } match (self.at, self.height, self.rotation) { (None, _, _) => Prompt::new("Specify start point of text", Accept::POINT).kw(&["Justify", "Style"]), diff --git a/crates/engine/tests/attdef_justify_style.rs b/crates/engine/tests/attdef_justify_style.rs index 7ce7aefb3..e419a95ff 100644 --- a/crates/engine/tests/attdef_justify_style.rs +++ b/crates/engine/tests/attdef_justify_style.rs @@ -214,3 +214,32 @@ fn typed_style_that_does_not_exist_asks_again() { s.cmdline("0,0").unwrap(); assert_eq!(last_attdef(&s).text.style, "ROMANS"); } + +/// The keywords a command's Justify prompt offers, from `[A/B/...]` in its prompt text. +fn justify_options(s: &Session) -> Vec { + let p = s.prompt_text(); + let inner = p.split_once('[').and_then(|(_, r)| r.split_once(']')).map(|(i, _)| i).unwrap_or(""); + inner.split('/').map(str::to_string).collect() +} + +/// `-ATTDEF`'s Justify prompt doesn't list Align and Fit, which it would only refuse (they run +/// between two points), while TEXT's still offers every option (#1720). +#[test] +fn attdef_justify_prompt_leaves_out_align_and_fit_but_text_keeps_them() { + let mut s = session(); + typed_to_start_point(&mut s); + s.cmdline("J").unwrap(); + let opts = justify_options(&s); + assert!(opts.iter().any(|o| o == "Left") && opts.iter().any(|o| o == "MC"), "{opts:?}"); + assert!(!opts.iter().any(|o| o == "Align" || o == "Fit"), "{opts:?}"); + // A typed A or F is still refused. + s.cmdline("A").unwrap(); + assert!(s.log.iter().any(|l| l.contains("Align and Fit")), "{:?}", s.log); + s.cmdline("*Cancel*").ok(); + + let mut t = session(); + t.cmdline("text").unwrap(); + t.cmdline("J").unwrap(); + let opts = justify_options(&t); + assert!(opts.iter().any(|o| o == "Align") && opts.iter().any(|o| o == "Fit"), "{opts:?}"); +}