Align Text > Angle asks for the angle instead of failing with a missing-parameter error (#478) (#582)

Squash of PR #582 by @MarekSpodBiedry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MarekSpodBiedry 2026-10-11 20:01:51 +02:00 committed by GitHub
parent b23b45e976
commit 3f781c3395
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 1 deletions

View File

@ -94,7 +94,8 @@ pub fn specs() -> Vec<CommandSpec> {
CommandSpec::new("dimtedit.home", "Home", |s, p| run_tedit(s, p, "home")).menu(&["Dimension", "Align Text", "Home"]).params("{handles?}"),
CommandSpec::new("dimtedit.angle", "Angle", |s, p| run_tedit(s, p, "angle"))
.menu(&["Dimension", "Align Text", "Angle"])
.params("{handles?, angle: degrees}"),
.params("{handles?, angle: degrees}")
.interactive(|_| Ok(Box::new(tedit::TEditM::angle()))),
CommandSpec::new("dimtedit.left", "Left", |s, p| run_tedit(s, p, "left")).menu(&["Dimension", "Align Text", "Left"]).params("{handles?}"),
CommandSpec::new("dimtedit.center", "Center", |s, p| run_tedit(s, p, "center"))
.menu(&["Dimension", "Align Text", "Center"])

View File

@ -15,6 +15,11 @@ pub(super) struct TEditM {
}
impl TEditM {
/// Align Text > Angle: select the dimension (or use the preselected one), then ask for the angle.
pub(super) fn angle() -> Self {
Self { dim: None, asking_angle: true }
}
fn run(&self, s: &mut Session, mut p: Value) -> Result<Step> {
let Some(h) = self.dim else { return Ok(Step::Cancel) };
if let Some(o) = p.as_object_mut() {

View File

@ -49,3 +49,22 @@ fn dimtedit_moves_justifies_rotates_and_homes_typed_text() {
assert!(s.running.is_none());
assert_eq!(the_dim(&s).overrides.get("textJust").and_then(|v| v.as_i64()), Some(0));
}
#[test]
fn align_text_angle_menu_entry_asks_for_the_angle() {
let mut s = Session::new();
s.script("dimlinear 0,0 10,0 5,3\n").unwrap();
let h = s.doc().unwrap().model.iter().find(|e| matches!(e.kind, EntityKind::Dimension(_))).unwrap().handle;
// With the dimension preselected, the menu entry (started with no parameters) asks for the angle.
s.set_selection(vec![h]);
s.start("dimtedit.angle").unwrap();
assert!(s.prompt_text().contains("Specify angle for dimension text"), "{}", s.prompt_text());
s.script("30\n").unwrap();
assert!(s.running.is_none());
assert!((the_dim(&s).text_rotation - 30f64.to_radians()).abs() < 1e-9);
// Without a selection it asks for the dimension first.
s.set_selection(vec![]);
s.start("dimtedit.angle").unwrap();
assert!(s.prompt_text().contains("Select dimension"), "{}", s.prompt_text());
}