diff --git a/crates/engine/src/cmd/trimextend.rs b/crates/engine/src/cmd/trimextend.rs index b6c36f5f2..d89e6b87f 100644 --- a/crates/engine/src/cmd/trimextend.rs +++ b/crates/engine/src/cmd/trimextend.rs @@ -227,6 +227,8 @@ enum Stage { Edges(Vec), /// Fence points so far. Fence(Vec), + /// Quick mode's two-point fence, started by a pick in empty space: its first point. + QuickFence(Vec2), /// A crossing window: its first corner once picked. Crossing(Option), Mode, @@ -363,6 +365,7 @@ impl Interactive for TrimM { None => Prompt::new("Specify first fence point", Accept::POINT), Some(l) => Prompt::new("Specify next fence point", Accept::POINT).kw(&["Undo"]).base(*l), }, + Stage::QuickFence(a) => Prompt::new("Specify next fence point", Accept::POINT).base(*a), Stage::Crossing(None) => Prompt::new("Specify first corner", Accept::POINT), Stage::Crossing(Some(_)) => Prompt::new("Specify opposite corner", Accept::POINT), Stage::Mode => { @@ -462,6 +465,16 @@ impl Interactive for TrimM { } Ok(Step::Continue) } + Stage::QuickFence(a) => { + self.stage = Stage::Pick; + if let Input::Point(b) = i { + let r = self.step(s, |m, s| fence(s, &[a, b], extending, m.edges(quick, implied), quick).map(|_| ())); + if let Err(e) = r { + s.echo(e.to_string()); + } + } + Ok(Step::Continue) + } Stage::Crossing(first) => { match (first, i) { (None, Input::Point(p)) => self.stage = Stage::Crossing(Some(p)), @@ -482,8 +495,9 @@ impl Interactive for TrimM { let ap = s.pixel_size() * s.settings.pickbox.max(1.0) * 1.5; let space = s.space(); let Some(h) = s.pick_object(&space, p, ap)? else { - // A pick in empty space opens a crossing window there. - self.stage = Stage::Crossing(Some(p)); + // A pick in empty space starts a two-point fence in Quick mode (as in + // AutoCAD, #1594) and a crossing window in Standard mode. + self.stage = if quick { Stage::QuickFence(p) } else { Stage::Crossing(Some(p)) }; return Ok(Step::Continue); }; let r = self.step(s, |m, s| apply(s, h, p, extending, m.edges(quick, implied), quick).map(|_| ())); @@ -532,6 +546,7 @@ impl Interactive for TrimM { .windows(2) .filter_map(|w| Some(line(*w.first()?, *w.get(1)?))) .collect(), + Stage::QuickFence(a) => vec![line(*a, c)], Stage::Crossing(Some(a)) => vec![lwpoly(rect_vertices(*a, c), true)], _ => Vec::new(), } diff --git a/crates/engine/tests/it/trim_extend_options.rs b/crates/engine/tests/it/trim_extend_options.rs index 5302a68c9..6fe76ee17 100644 --- a/crates/engine/tests/it/trim_extend_options.rs +++ b/crates/engine/tests/it/trim_extend_options.rs @@ -112,10 +112,33 @@ fn crossing_window_trims_what_it_touches() { s.script("TRIM C 4,-1 6,1\n\n").unwrap(); assert!(s.running.is_none(), "{}", s.prompt_text()); assert_eq!(lines(&s), with_edges(&[((-5.0, 0.0), (0.0, 0.0)), ((-5.0, 2.0), (15.0, 2.0)), ((10.0, 0.0), (15.0, 0.0))])); - // A pick in empty space opens a crossing window too. +} + +#[test] +fn a_pick_in_empty_space_starts_a_fence_in_quick_mode_and_a_window_in_standard_mode() { + // #1594: Quick mode's two-point fence trims what it crosses and returns to the first prompt. + for cmd in ["TRIM", "EXTEND"] { + let mut s = ladder(); + s.cmdline(cmd).unwrap(); + s.cmdline("4,-4").unwrap(); + assert!(s.prompt_text().contains("Specify next fence point"), "{cmd}: {}", s.prompt_text()); + } let mut s = ladder(); - s.script("TRIM 4,-4 6,1\n\n").unwrap(); + s.script("TRIM 4,-4 6,1\n").unwrap(); + assert!(s.prompt_text().contains("Select object to trim"), "{}", s.prompt_text()); + s.cmdline("").unwrap(); assert_eq!(lines(&s), with_edges(&[((-5.0, 0.0), (0.0, 0.0)), ((-5.0, 2.0), (15.0, 2.0)), ((10.0, 0.0), (15.0, 0.0))])); + // EXTEND's fence extends both lines it crosses to the boundary at x = 10. + let mut s = session(&["10,-5 10,5", "0,0 4,0", "0,2 4,2"]); + s.script("EXTEND 3,-1 3,3\n").unwrap(); + assert!(s.prompt_text().contains("Select object to extend"), "{}", s.prompt_text()); + s.cmdline("").unwrap(); + assert!(s.running.is_none(), "{}", s.prompt_text()); + assert_eq!(lines(&s), vec![((0.0, 0.0), (10.0, 0.0)), ((0.0, 2.0), (10.0, 2.0)), ((10.0, -5.0), (10.0, 5.0))]); + // Standard mode keeps the crossing window. + let mut s = ladder(); + s.script("TRIM O S\n\n4,-4\n").unwrap(); + assert!(s.prompt_text().contains("Specify opposite corner"), "{}", s.prompt_text()); } #[test]