From 95b23f28d6eb199f7734533f4c6628973ce97927 Mon Sep 17 00:00:00 2001 From: DuBearte <130190089+DuBearte@users.noreply.github.com> Date: Wed, 21 Oct 2026 22:07:38 +0000 Subject: [PATCH] Rename box: Tab (and leaving the box) keeps the new name (#3313) (#3336) * claim: #3313 * fix(ui): the Rename box keeps the new name when it loses focus (#3313) Only Enter committed a rename: Tab (and anything else that moved focus away) dropped the typed name. Leaving the box now keeps it, as a click elsewhere already did; Escape still cancels. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: bherbruck --- crates/ui-egui/src/menu_tests.rs | 35 +++++++++++++++++++++++++++++++ crates/ui-egui/src/ui_kit/menu.rs | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rs index d4f7f1d68..c70b3e799 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 = 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.rs index 4495b010e..c8f534dd1 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)) {