Skip to content

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

Preferences: typing in a number field edits it instead of searching (#8662) (#8663)

N3MI-DG0818ad0ed404
diff --git a/crates/ui-egui/src/prefs_search.rs b/crates/ui-egui/src/prefs_search.rs
index 6eca73243c..eee7bf6ed8 100644
--- a/crates/ui-egui/src/prefs_search.rs
+++ b/crates/ui-egui/src/prefs_search.rs
@@ -746,6 +746,22 @@ mod tests {
assert_eq!(h.app.prefs_window.section, crate::prefs::PAGE_GRAPHICS, "Escape returns to the page from before the search");
}
+ /// Typing in a number field (the largest STEP file) edits that field instead of starting
+ /// a search.
+ #[test]
+ fn preferences_number_fields_keep_typed_text() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.home.open = false;
+ crate::prefs::open_at(&mut h.app, crate::prefs::PAGE_GENERAL);
+ h.frames(2);
+ let field = crate::scenario::rect_of("prefs:max_step_file_mb").expect("STEP limit field");
+ h.step(&serde_json::json!({"click": [field.center().x, field.center().y]})).expect("click the field");
+ h.frames(2);
+ h.step(&serde_json::json!({"text": "7"})).expect("type");
+ h.frames(2);
+ assert!(h.app.prefs_window.filter.is_empty(), "typed `{}` into the search", h.app.prefs_window.filter);
+ }
+
/// The selected match is scrolled to when the arrows move it, not on every frame, so the
/// wheel can scroll the results away from it.
#[test]
diff --git a/crates/ui-egui/src/ui_kit/fields.rs b/crates/ui-egui/src/ui_kit/fields.rs
index 90a501cdf7..8e434be23e 100644
--- a/crates/ui-egui/src/ui_kit/fields.rs
+++ b/crates/ui-egui/src/ui_kit/fields.rs
@@ -852,6 +852,9 @@ pub(crate) fn number_field<T: egui::emath::Numeric>(
suffix: &str,
) -> Response {
let response = ui.add(egui::DragValue::new(value).range(range).speed(speed).suffix(suffix).custom_parser(crate::prefs::parse_number));
+ if response.has_focus() {
+ crate::prefs_search::note_key_sink(ui.ctx());
+ }
Tokens::get().input_bevel(ui, &response);
response.widget_info(|| {
let mut info = egui::WidgetInfo::drag_value(ui.is_enabled(), value.to_f64());