From 8db82ebf7c86ff7e5eb84ee07115d8d55445f0d0 Mon Sep 17 00:00:00 2001 From: jayzed80 Date: Sun, 15 Nov 2026 09:38:01 +0000 Subject: [PATCH] TRIM/EXTEND: Space enters an option at the mode, projection and edge prompts (#3092) --- crates/engine/src/cmd/trimextend.rs | 7 +-- crates/ui-egui/tests/it/main.rs | 1 + crates/ui-egui/tests/it/space_at_options.rs | 59 +++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 crates/ui-egui/tests/it/space_at_options.rs diff --git a/crates/engine/src/cmd/trimextend.rs b/crates/engine/src/cmd/trimextend.rs index eab957589..fbc249eee 100644 --- a/crates/engine/src/cmd/trimextend.rs +++ b/crates/engine/src/cmd/trimextend.rs @@ -8,6 +8,7 @@ use cadcraft_doc::{Drawing, EntityKind, Handle}; use cadcraft_geom::{Bounds2, Line, Vec2, line_line}; use serde_json::{Value, json}; +use super::curves::KW; use super::helpers::{line, lwpoly, rect_vertices}; use super::modify::{Edges, extend, trim}; use super::{bad, point_param, points_param}; @@ -360,7 +361,7 @@ impl Interactive for TrimM { Stage::Crossing(Some(_)) => Prompt::new("Specify opposite corner", Accept::POINT), Stage::Mode => { let msg = if self.extend { "Enter an extend mode option" } else { "Enter a trim mode option" }; - Prompt::new(msg, Accept::TEXT).kw(&["Quick", "Standard"]).default(if quick_mode(s) { "Quick" } else { "Standard" }) + Prompt::new(msg, KW).kw(&["Quick", "Standard"]).default(if quick_mode(s) { "Quick" } else { "Standard" }) } Stage::Project => { let cur = match proj_mode(s) { @@ -368,9 +369,9 @@ impl Interactive for TrimM { 2 => "View", _ => "Ucs", }; - Prompt::new("Enter a projection option", Accept::TEXT).kw(&["None", "Ucs", "View"]).default(cur) + Prompt::new("Enter a projection option", KW).kw(&["None", "Ucs", "View"]).default(cur) } - Stage::Edge => Prompt::new("Enter an implied edge extension mode", Accept::TEXT).kw(&["Extend", "No extend"]).default(if edge_mode(s) { + Stage::Edge => Prompt::new("Enter an implied edge extension mode", KW).kw(&["Extend", "No extend"]).default(if edge_mode(s) { "Extend" } else { "No extend" diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index a368c491a..7753e2a1e 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -32,6 +32,7 @@ mod selection_cycling; mod shared_controls; mod shortcut_menus; mod shortcuts_checked; +mod space_at_options; mod status_bar_toggles; mod style_dialogs; mod system_cursor; diff --git a/crates/ui-egui/tests/it/space_at_options.rs b/crates/ui-egui/tests/it/space_at_options.rs new file mode 100644 index 000000000..12e2a8d9a --- /dev/null +++ b/crates/ui-egui/tests/it/space_at_options.rs @@ -0,0 +1,59 @@ +//! Space is Enter at TRIM's and EXTEND's option prompts, as at AutoCAD's (#3092): typing `O`, +//! Space, `S`, Space switches to Standard mode instead of typing a space into the command line. + +use cadcraft_engine::Session; +use cadcraft_ui_egui::{CadApp, Services}; +use egui::{Key, Modifiers, vec2}; +use egui_kittest::Harness; + +fn harness() -> Harness<'static, CadApp> { + let app = CadApp::new(Session::new(), Services::default()); + let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( + |ui, app: &mut CadApp| { + app.logic(ui.ctx()); + app.ui(ui); + }, + app, + ); + h.run_steps(3); + h +} + +/// Type `text` at the keyboard: a space arrives as the Space key and as text, like a real press. +fn type_keys(h: &mut Harness<'static, CadApp>, text: &str) { + for c in text.chars() { + if c == ' ' { + h.event(egui::Event::Key { key: Key::Space, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }); + } + h.event(egui::Event::Text(c.to_string())); + h.run_steps(1); + } + h.run_steps(1); +} + +fn header(h: &Harness<'static, CadApp>, name: &str) -> i64 { + h.state().session.doc().unwrap().header.i64(name, -1) +} + +fn prompt(h: &Harness<'static, CadApp>) -> String { + h.state().session.current_prompt().map(|p| p.message).unwrap_or_default() +} + +#[test] +fn space_answers_trim_and_extend_option_prompts() { + let mut h = harness(); + type_keys(&mut h, "trim o s "); + assert_eq!(h.state().cmd.buffer, "", "Space typed a space instead of entering the option"); + assert_eq!(header(&h, "TRIMEXTENDMODE"), 0, "S chose Standard mode"); + // Standard mode asks for cutting edges; Enter selects all, then Project and Edge. + type_keys(&mut h, " p n e e "); + assert_eq!(h.state().cmd.buffer, ""); + assert_eq!(header(&h, "PROJMODE"), 0, "N chose no projection"); + assert_eq!(header(&h, "EDGEMODE"), 1, "E chose Extend"); + assert!(prompt(&h).starts_with("Select object to trim"), "back at the trim prompt: {}", prompt(&h)); + h.key_press(Key::Escape); + h.run_steps(2); + type_keys(&mut h, "extend o q "); + assert_eq!(h.state().cmd.buffer, ""); + assert_eq!(header(&h, "TRIMEXTENDMODE"), 1, "Q chose Quick mode in EXTEND"); +}