mirror of
https://github.com/storytold/cadcraft.git
synced 2026-11-29 17:53:59 +01:00
-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.
This commit is contained in:
1 parent
e65132c77a
commit
f0c1b4ff29
3 files changed
+39
-6
No files matched your search
@@ -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 => {}
|
||||
}
|
||||
|
||||
@@ -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"]),
|
||||
|
||||
@@ -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<String> {
|
||||
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:?}");
|
||||
}
|
||||
Reference in new issue
Block a user