SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Preferences: search finds settings in rows without a label (#9265) (#9318)
Logan Night202e713cf1d7
diff --git a/crates/ui-egui/src/prefs_search.rs b/crates/ui-egui/src/prefs_search.rsindex eee7bf6ed8..ad9514bf44 100644--- a/crates/ui-egui/src/prefs_search.rs+++ b/crates/ui-egui/src/prefs_search.rs@@ -65,6 +65,10 @@ struct State {/// A heading matched, so the controls under it stay visible until the next heading.heading_open: bool,hiding: u32,+ /// Set while a row with no label of its own runs hidden: what its controls say stands in for it.+ unlabelled: u32,+ /// Rows drawn this page with no label, so each gets a key of its own.+ unlabelled_rows: u32,key: String,hits: u32,page_index: usize,@@ -259,6 +263,7 @@ pub(crate) fn begin_page(ui: &Ui, index: usize, label: &str) {state.page_index = index;state.page = label.to_string();state.page_shown = false;+ state.unlabelled_rows = 0;state.section.clear();state.key.clear();state.section_matches = false;@@ -271,6 +276,7 @@ pub(crate) fn begin_section(ui: &Ui, title: &str) {let matches = text_hit(ui, title);with(ui, |state| {state.section = title.to_string();+ state.unlabelled_rows = 0;state.section_matches = matches || state.force > 0;state.section_shown.clear();// A dropdown with no row of its own must not store its value under the last row's key.@@ -335,6 +341,53 @@ pub(crate) fn set_control(ui: &Ui, label: &str) {with(ui, |state| state.key = format!("{}\n{}\n{}", state.page, state.section, label));}+/// Key a row that has no label of its own by its place in the section, so two of them do not share+/// one stored text. Returns the text to match the row on (still empty).+pub(crate) fn set_unlabelled_control(ui: &Ui) {+ with(ui, |state| {+ state.unlabelled_rows += 1;+ state.key = format!("{}\n{}\n#{}", state.page, state.section, state.unlabelled_rows);+ });+}++pub(crate) fn push_unlabelled(ui: &Ui) {+ with(ui, |state| state.unlabelled = state.unlabelled.saturating_add(1));+}++pub(crate) fn pop_unlabelled(ui: &Ui) {+ with(ui, |state| state.unlabelled = state.unlabelled.saturating_sub(1));+}++/// A control inside a row with no label says what it is. Stored for the row, so the next pass can+/// match the row on those words and draw it, as it does for a dropdown's current value.+pub(crate) fn note_unlabelled(ui: &Ui, texts: &[&str]) {+ if !querying(ui) {+ return;+ }+ with(ui, |state| {+ if state.hiding == 0 || state.unlabelled == 0 || state.key.is_empty() {+ return;+ }+ let mut stored = state.extras.get(&state.key).cloned().unwrap_or_default();+ let was = extra_hit_text(state, Some(stored.as_str()));+ for text in texts.iter().filter(|text| !text.is_empty()) {+ if !stored.contains(text) {+ if !stored.is_empty() {+ stored.push(' ');+ }+ stored.push_str(text);+ }+ }+ let now = extra_hit_text(state, Some(stored.as_str()));+ let key = state.key.clone();+ state.extras.insert(key, stored);+ if was != now {+ state.child_matched = true;+ state.dirty = true;+ }+ });+}+/// Draw this control. A miss returns false and draws nothing; the caller still runs the control/// off-screen when it needs the widget's current value.pub(crate) fn visible(ui: &mut Ui, texts: &[&str]) -> bool {@@ -847,4 +900,43 @@ mod tests {assert!(h.widget("Reverse zoom direction").is_none());assert!(h.widget("Units of new designs").is_some());}+ /// Settings drawn in a row with no label of their own are found by the words they show (#9265).+ #[test]+ fn preferences_search_finds_settings_in_rows_without_a_label() {+ let mut h = crate::scenario::Harness::new();+ h.app.home.open = false;+ crate::prefs::open_at(&mut h.app, crate::prefs::PAGE_INTERFACE);+ h.frames(2);+ // Drawn, not merely present: a hidden row's controls still exist, far off screen.+ let drawn = |h: &crate::scenario::Harness, label: &str| {+ let body = crate::scenario::rect_of("dialog:page_body");+ h.widget(label).is_some_and(|[x, y]| body.is_none_or(|body| body.contains(egui::pos2(x as f32, y as f32))))+ };+ let rows = [+ ("status bar", "Status bar"),+ ("sketch tab shown", "Keep the Sketch tab shown"),+ ("search results", "Show search results in the ribbon"),+ ("play history", "Play History button in the History controls"),+ ("view's corner", "OK and Cancel in the view's corner"),+ ("highlight active", "Highlight active ribbon commands"),+ ("reveal on hover", "Reveal on hover"),+ ];+ for (query, label) in rows {+ h.app.prefs_window.filter = query.into();+ h.frames(4);+ assert!(drawn(&h, label), "searching '{query}' should show '{label}'");+ }+ h.app.prefs_window.filter = "status bar".into();+ h.frames(4);+ assert!(!drawn(&h, "Keep the Sketch tab shown"), "a row that does not match stays out of the result");+ // Three unlabelled rows sit under one labelled row: each is found on its own words only.+ h.app.prefs_window.filter = "sketch tab shown".into();+ h.frames(4);+ assert!(drawn(&h, "Keep the Sketch tab shown"));+ assert!(!drawn(&h, "Highlight active ribbon commands"), "its neighbour is not a match");+ assert!(!drawn(&h, "Show search results in the ribbon"), "its neighbour is not a match");+ h.app.prefs_window.filter = "zzzz-no-setting".into();+ h.frames(4);+ assert!(!drawn(&h, "Status bar"), "a miss shows nothing");+ }}diff --git a/crates/ui-egui/src/ui_kit/checks.rs b/crates/ui-egui/src/ui_kit/checks.rsindex ae109d5105..7883bcb7a3 100644--- a/crates/ui-egui/src/ui_kit/checks.rs+++ b/crates/ui-egui/src/ui_kit/checks.rs@@ -58,6 +58,7 @@ pub(crate) fn checkbox(ui: &mut Ui, label: &str, value: &mut bool) -> Response {/// Mixed values become checked when activated; the caller owns whether selection is mixed./// Tokens: space_14/3/2/6, radius_sm, control_fill/border, form_primary/ink, hover, on_accent.pub(crate) fn checkbox_indeterminate(ui: &mut Ui, label: &str, value: &mut bool, mixed: bool) -> Response {+ crate::prefs_search::note_unlabelled(ui, &[label]);if crate::prefs_search::querying(ui) && !crate::prefs_search::visible(ui, &[label]) {return crate::prefs_search::hidden_response(ui);}diff --git a/crates/ui-egui/src/ui_kit/choice.rs b/crates/ui-egui/src/ui_kit/choice.rsindex af451912c9..e8cea12076 100644--- a/crates/ui-egui/src/ui_kit/choice.rs+++ b/crates/ui-egui/src/ui_kit/choice.rs@@ -33,6 +33,7 @@ pub(crate) struct Segments<'a> {}pub(crate) fn segmented(ui: &mut Ui, selected: &mut usize, options: &[&str], config: Segments<'_>) -> bool {+ crate::prefs_search::note_unlabelled(ui, options);if crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, options) {return false;}diff --git a/crates/ui-egui/src/ui_kit/layout.rs b/crates/ui-egui/src/ui_kit/layout.rsindex 5e22169dff..f598e3c266 100644--- a/crates/ui-egui/src/ui_kit/layout.rs+++ b/crates/ui-egui/src/ui_kit/layout.rs@@ -222,9 +222,21 @@ pub(crate) fn choice_row(ui: &mut Ui, label: &str, id: &str, selected: &mut usizpub(super) fn sized_row<R>(ui: &mut Ui, text: &str, height: f32, control: impl FnOnce(&mut Ui) -> R) -> R {let mut passthrough = false;if crate::prefs_search::querying(ui) {- crate::prefs_search::set_control(ui, text);+ // A row with no label has no words to match; its controls supply them (#9265).+ let unlabelled = text.is_empty();+ if unlabelled {+ crate::prefs_search::set_unlabelled_control(ui);+ } else {+ crate::prefs_search::set_control(ui, text);+ }if !crate::prefs_search::visible(ui, &[text]) {+ if unlabelled {+ crate::prefs_search::push_unlabelled(ui);+ }let result = crate::prefs_search::run_hidden(ui, text, control);+ if unlabelled {+ crate::prefs_search::pop_unlabelled(ui);+ }crate::prefs_search::recheck(ui, &[text]);return result;}