SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Edit Extrude: close on the first Escape (#9084) (#9757)
froglemonade23ccf04d4b29c
diff --git a/assets/locales/pending/completion-escape-closes-window.json b/assets/locales/pending/completion-escape-closes-window.jsonnew file mode 100644index 0000000000..1e49a4fd9e--- /dev/null+++ b/assets/locales/pending/completion-escape-closes-window.json@@ -0,0 +1,9 @@+{+ "ar": { "↑ ↓ choose · Enter applies this value": "↑ ↓ اختيار · Enter يطبّق هذه القيمة" },+ "de": { "↑ ↓ choose · Enter applies this value": "↑ ↓ auswählen · Eingabe übernimmt diesen Wert" },+ "en": { "↑ ↓ choose · Enter applies this value": "↑ ↓ choose · Enter applies this value" },+ "he": { "↑ ↓ choose · Enter applies this value": "↑ ↓ בחירה · Enter מחיל את הערך הזה" },+ "ja": { "↑ ↓ choose · Enter applies this value": "↑ ↓ 選択 · Enter この値を適用" },+ "vi": { "↑ ↓ choose · Enter applies this value": "↑ ↓ để chọn · Enter để áp dụng giá trị này" },+ "zh": { "↑ ↓ choose · Enter applies this value": "↑ ↓ 选择 · Enter 应用此值" }+}diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 4a3ff51cc8..b97a244ea7 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -6845,6 +6845,36 @@ mod refused_ok_tests {}}+ /// One Escape closes an edit dialog opened from its History row, also when its value names a parameter+ /// and the field lists the longer names (`T` lists `tan(`, #9084).+ #[test]+ fn one_escape_closes_an_edit_dialog_whose_value_names_a_parameter() {+ for name in ["Plate", "Corners", "Hole"] {+ let mut h = Harness::new();+ for (command, params) in [+ ("parameters.add", json!({"name": "T", "expression": "3 mm"})),+ ("parameters.add", json!({"name": "R", "expression": "5 mm"})),+ ("sketch.create", json!({"plane": "XY"})),+ ("sketch.rectangle.two_point", json!({"p0": [-40, -25], "p1": [40, 25]})),+ ("sketch.finish", json!({})),+ ("solid.extrude", json!({"distance": "T", "name": "Plate"})),+ ("solid.fillet", json!({"edges": [[40, 25, 1.5], [-40, 25, 1.5]], "radius": "R", "name": "Corners"})),+ ("solid.hole", json!({"position": [0, 0, 3], "diameter": 3.4, "name": "Hole"})),+ ] {+ h.app.run(command, params).unwrap();+ }+ h.frames(2);+ steps(&mut h, &[json!({"click": {"handle": format!("timeline:{name}")}, "double": true}), json!({"frames": 30})]);+ assert!(h.app.dialog.as_ref().is_some_and(|d| d.editing.is_some()), "{name}: the edit dialog opened");+ if name != "Hole" {+ assert!(h.ctx.memory(|m| m.focused()).is_some(), "{name}: its value field has the keyboard");+ assert!(crate::expression_complete::popup_state(&h.ctx).is_some(), "{name}: the field lists longer names");+ }+ steps(&mut h, &[json!({"key": "Escape"}), json!({"frames": 2})]);+ assert!(h.app.dialog.as_ref().is_none_or(|d| d.editing.is_none()), "{name}: one Escape closes the dialog");+ }+ }+fn set_depth(h: &mut Harness, depth: &str) {steps(h, &[json!({"click": {"handle": "dialog:Depth"}}), json!({"key": "A", "cmd": true}), json!({"text": depth})]);}diff --git a/crates/ui-egui/src/expression_complete.rs b/crates/ui-egui/src/expression_complete.rsindex 71c8f66ff9..cafdf46abb 100644--- a/crates/ui-egui/src/expression_complete.rs+++ b/crates/ui-egui/src/expression_complete.rs@@ -35,6 +35,11 @@ struct Popup {empty: bool,/// Down arrow in the empty box opened it: every named parameter, however many (#9246).every: bool,+ /// The box was typed in since it took the focus. Until then an unarmed list only shows+ /// what longer names there are, for a value the window filled in (`T` in Edit Extrude+ /// lists `tan(`): Escape passes it by and closes the window as it would without the list,+ /// as Enter and Tab do (#9084).+ typed: bool,}fn popup_id() -> egui::Id {@@ -105,6 +110,7 @@ pub(crate) fn begin_frame(ctx: &egui::Context) {// Unarmed, the typed word is complete: Enter submits it and Tab moves on.Key::Enter | Key::Tab if !popup.armed => continue,Key::Enter | Key::Tab => popup.accept = true,+ Key::Escape if !popup.armed && !popup.typed => continue,Key::Escape => {popup.dismissed = true;popup.accept = false;@@ -169,6 +175,7 @@ pub(crate) fn complete(ui: &mut egui::Ui, resp: &egui::Response, text: &mut Stri// Dismissed suggestions stay closed until this box is typed in: another control rewriting// its text (a slider dragged while the box keeps the focus) or a moved caret is no reason.let dismissed = previous.as_ref().is_some_and(|p| p.dismissed) && !resp.changed();+ let typed = resp.changed() || previous.as_ref().is_some_and(|p| p.typed);// What the word follows, blanks aside.let before = text.chars().take(start).filter(|c| !c.is_whitespace()).last();// A word that is already a complete name opens unarmed: Enter submits it as typed. A unit is@@ -191,7 +198,9 @@ pub(crate) fn complete(ui: &mut egui::Ui, resp: &egui::Response, text: &mut Strikeyed: false,empty: false,every: false,+ typed,});+ popup.typed = typed;popup.empty = text.is_empty();popup.armed = popup.keyed || armed;// Never over a control being dragged: the drag dismisses them.@@ -251,10 +260,13 @@ pub(crate) fn complete(ui: &mut egui::Ui, resp: &egui::Response, text: &mut Stripopup.armed.then_some(popup.selected),&options,// Unarmed, the typed word is complete and Enter submits it; an arrow key arms the list.+ // Escape is the window's until the box is typed in.crate::i18n::tr_label(if popup.armed {"↑ ↓ choose · Enter / Tab complete · Esc dismiss"- } else {+ } else if popup.typed {"↑ ↓ choose · Enter applies what you typed · Esc dismiss"+ } else {+ "↑ ↓ choose · Enter applies this value"}),) && pick.is_none()&& !released_after_press@@ -542,6 +554,26 @@ mod tests {}}+ /// A list that opened by itself on a value the window filled in leaves Escape to the window+ /// (#9084); once the box is typed in, Escape dismisses the list first.+ #[test]+ fn escape_passes_an_unarmed_list_until_the_box_is_typed_in() {+ let mut e = Editor::new("width");+ assert_eq!(e.popup().map(|(_, armed)| armed), Some(false));+ e.key(Key::Escape);+ assert!(e.leaked.contains(&Key::Escape));+ assert!(!e.ctx.memory(|m| m.has_focus(e.id)));++ let mut e = Editor::new("widt");+ e.frame(vec![egui::Event::Text("h".into())]);+ assert_eq!(e.text, "width");+ assert_eq!(e.popup().map(|(_, armed)| armed), Some(false));+ e.key(Key::Escape);+ assert!(e.leaked.is_empty());+ assert!(!showing(&e.ctx, e.id));+ assert!(e.ctx.memory(|m| m.has_focus(e.id)));+ }+/// From the unarmed popup an arrow key picks a row (Down the first, Up the last); Enter or/// Tab then complete it as usual.#[test]