SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Rename box: Tab (and leaving the box) keeps the new name (#3313) (#3336)
DuBearte95b23f28d6eb
diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rsindex d4f7f1d687..c70b3e7996 100644--- a/crates/ui-egui/src/menu_tests.rs+++ b/crates/ui-egui/src/menu_tests.rs@@ -848,6 +848,41 @@ fn menus_near_the_window_corner_open_inward() {}}+/// #3313: renaming a body by typing in the Rename box and pressing Enter (or Tab) renames it.+#[test]+fn typing_a_new_body_name_and_enter_renames_it() {+ for confirm in ["Enter", "Tab"] {+ let mut h = crate::scenario::Harness::new();+ h.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10})).unwrap();+ let b = h.app.session.model.state().bodies[0].name.clone();+ h.app.run("select.set", json!({"items": [{"type": "body", "name": b}]})).unwrap();+ h.frames(2);+ h.step(&json!({"key": "F2"})).unwrap();+ h.frames(2);+ assert!(h.app.menu.rename.is_some(), "F2 opens the Rename box");+ h.step(&json!({"text": "Lid"})).unwrap();+ h.frames(1);+ h.step(&json!({"key": confirm})).unwrap();+ h.frames(2);+ let names: Vec<String> = h.app.session.model.state().bodies.iter().map(|b| b.name.clone()).collect();+ assert_eq!(names, ["Lid"], "{confirm} renames the body; status {:?}", h.app.status);+ }+ // Escape still cancels.+ let mut h = crate::scenario::Harness::new();+ h.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10})).unwrap();+ let b = h.app.session.model.state().bodies[0].name.clone();+ h.app.run("select.set", json!({"items": [{"type": "body", "name": b.clone()}]})).unwrap();+ h.frames(2);+ h.step(&json!({"key": "F2"})).unwrap();+ h.frames(2);+ h.step(&json!({"text": "Lid"})).unwrap();+ h.frames(1);+ h.step(&json!({"key": "Escape"})).unwrap();+ h.frames(2);+ assert!(h.app.menu.rename.is_none());+ assert_eq!(h.app.session.model.state().bodies[0].name, b, "Escape keeps the old name");+}+#[test]fn contribution_picked_faces_open_their_own_feature_after_later_modifiers() {use solidcraft_engine::{Sel, geom::Vec3};diff --git a/crates/ui-egui/src/ui_kit/menu.rs b/crates/ui-egui/src/ui_kit/menu.rsindex 4495b010e2..c8f534dd11 100644--- a/crates/ui-egui/src/ui_kit/menu.rs+++ b/crates/ui-egui/src/ui_kit/menu.rs@@ -375,7 +375,8 @@ pub(crate) fn rename_menu(ui: &mut Ui, value: &mut String, focused: &mut bool) -response.request_focus();*focused = true;}- if ui.input(|i| i.key_pressed(egui::Key::Enter)) {+ // Leaving the box with Tab keeps the new name as Enter does; only Escape cancels (#3313).+ if ui.input(|i| i.key_pressed(egui::Key::Enter)) || (response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Tab))) {done = Some(true);}if ui.input(|i| i.key_pressed(egui::Key::Escape)) {