Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

fix(ui): keep profile-name typing out of Preferences search (#9505) (#9568)

PapaEchof43198988db4
diff --git a/crates/ui-egui/src/settings_profiles_tests.rs b/crates/ui-egui/src/settings_profiles_tests.rs
index c9fc6dead8..bacbd7428f 100644
--- a/crates/ui-egui/src/settings_profiles_tests.rs
+++ b/crates/ui-egui/src/settings_profiles_tests.rs
@@ -330,6 +330,31 @@ fn starting_a_profile_command_opens_preferences_instead_of_failing() {
assert!(h.app.prefs_window.open);
}
+#[test]
+fn typing_a_profile_name_keeps_focus_out_of_preferences_search() {
+ let mut h = Harness::new();
+ h.app.home.open = false;
+ h.call("ui.prefs", json!({"open": "General"}));
+ h.frames(3);
+ h.step(&json!({"text": "profiles"})).expect("find Settings profiles");
+ h.frames(3);
+ h.step(&json!({"click": {"handle": "dialog:Name"}})).expect("focus the profile name");
+ h.frames(2);
+ let name_focus = h.ctx.memory(|memory| memory.focused()).expect("the name field has focus");
+ for text in ["Lap", "top"] {
+ h.step(&json!({"text": text})).expect("type a profile name");
+ h.frames(2);
+ assert_eq!(h.app.prefs_window.filter, "profiles", "profile-name text went to Preferences search");
+ assert_eq!(h.ctx.memory(|memory| memory.focused()), Some(name_focus), "the name field keeps focus");
+ }
+ assert!(h.widget("Laptop").is_some(), "the name field contains the typed name");
+ h.step(&json!({"widget": "Save"})).expect("save the profile");
+ h.frames(2);
+ assert_eq!(h.app.settings_profiles.active.as_deref(), Some("Laptop"));
+ assert_eq!(h.app.settings_profiles.names(), ["Laptop"]);
+ assert_eq!(h.app.prefs_window.filter, "profiles");
+}
+
#[test]
fn choosing_a_profile_in_preferences_applies_it() {
let mut h = Harness::new();
diff --git a/crates/ui-egui/src/ui_kit/fields.rs b/crates/ui-egui/src/ui_kit/fields.rs
index 69c37be779..54ff001a2c 100644
--- a/crates/ui-egui/src/ui_kit/fields.rs
+++ b/crates/ui-egui/src/ui_kit/fields.rs
@@ -667,6 +667,9 @@ fn editor_reserving(ui: &mut Ui, value: &mut String, hint: &str, completion: boo
ui.ctx().data_mut(|data| data.insert_temp(egui::Id::new("sc_focused_editor"), response.id));
}
super::text_menu::menu(ui, &mut response, value, super::text_menu::Field::LINE);
+ if response.has_focus() {
+ crate::prefs_search::note_key_sink(ui.ctx());
+ }
if completion && ui.is_enabled() {
ui.ctx().data_mut(|data| {
let id = egui::Id::new("sc_value_fields");