Skip to content

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

Preferences: search settings (#2218) (#6002)

taylorhayisc4fb42f6651b
diff --git a/assets/locales/en.json b/assets/locales/en.json
index d080c7cdec..1d34520542 100644
--- a/assets/locales/en.json
+++ b/assets/locales/en.json
@@ -1580,6 +1580,8 @@
"prefs.saving": "Autosave and recovery",
"prefs.scale_note": "Also Ctrl + / Ctrl − in the window. Buttons are 28 px at 100%.",
"prefs.scale_text": "Scale and text",
+ "prefs.search": "Search settings",
+ "prefs.search_empty": "No matching settings",
"prefs.select": "Select",
"prefs.select_one_item": "Select one item",
"prefs.selecting": "Selecting",
diff --git a/assets/locales/ja.json b/assets/locales/ja.json
index cf5fc021b3..37b76a432e 100644
--- a/assets/locales/ja.json
+++ b/assets/locales/ja.json
@@ -1580,6 +1580,8 @@
"prefs.saving": "自動保存と復元",
"prefs.scale_note": "ウィンドウ内では Ctrl + / Ctrl − でも変更できます。100% のボタンは 28 px です。",
"prefs.scale_text": "拡大率と文字",
+ "prefs.search": "設定を検索",
+ "prefs.search_empty": "一致する設定がありません",
"prefs.select": "選択",
"prefs.select_one_item": "項目を 1 つ選択",
"prefs.selecting": "選択",
diff --git a/assets/locales/pending/preferences-search.json b/assets/locales/pending/preferences-search.json
new file mode 100644
index 0000000000..f300ec832c
--- /dev/null
+++ b/assets/locales/pending/preferences-search.json
@@ -0,0 +1,22 @@
+{
+ "ar": {
+ "prefs.search": "البحث في الإعدادات",
+ "prefs.search_empty": "لا توجد إعدادات مطابقة"
+ },
+ "de": {
+ "prefs.search": "Einstellungen suchen",
+ "prefs.search_empty": "Keine passenden Einstellungen"
+ },
+ "he": {
+ "prefs.search": "חיפוש הגדרות",
+ "prefs.search_empty": "אין הגדרות תואמות"
+ },
+ "ko": {
+ "prefs.search": "설정 검색",
+ "prefs.search_empty": "일치하는 설정이 없습니다"
+ },
+ "vi": {
+ "prefs.search": "Tìm kiếm cài đặt",
+ "prefs.search_empty": "Không có cài đặt nào khớp"
+ }
+}
diff --git a/assets/locales/zh.json b/assets/locales/zh.json
index f45f43fbbb..c222ce52b6 100644
--- a/assets/locales/zh.json
+++ b/assets/locales/zh.json
@@ -1580,6 +1580,8 @@
"prefs.saving": "自动保存和恢复",
"prefs.scale_note": "也可在窗口中使用 Ctrl + / Ctrl −。100% 时按钮高度为 28 像素。",
"prefs.scale_text": "缩放与文字",
+ "prefs.search": "搜索设置",
+ "prefs.search_empty": "没有匹配的设置",
"prefs.select": "选择",
"prefs.select_one_item": "选择一个项目",
"prefs.selecting": "选择",
diff --git a/crates/ui-egui/src/agent_chat/settings.rs b/crates/ui-egui/src/agent_chat/settings.rs
index a65fbe8a55..86b78a01ec 100644
--- a/crates/ui-egui/src/agent_chat/settings.rs
+++ b/crates/ui-egui/src/agent_chat/settings.rs
@@ -273,7 +273,8 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) {
if !cfg!(target_arch = "wasm32") && app.preferences.ai_features {
#[cfg(not(target_arch = "wasm32"))]
{
- if app.agent_chat.detection.is_none() && app.agent_chat.detecting.is_none() {
+ let browsing = !crate::prefs_search::querying(ui) || app.prefs_window.section == crate::prefs::PAGE_AI;
+ if browsing && app.agent_chat.detection.is_none() && app.agent_chat.detecting.is_none() {
refresh(app, &ui.ctx().clone());
}
agents_section(app, ui);
diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs
index 642a34d856..6ceca109e9 100644
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@ -300,6 +300,14 @@ pub fn tr(id: &str) -> &str {
pub fn tr_label(label: &str) -> &str {
CURRENT.with(|current| current.get().label(label))
}
+
+/// Every English catalog entry `(id, text)`, for Preferences search to match a translation
+/// back to the words it was written in.
+pub(crate) fn each_english_message(mut f: impl FnMut(&str, &str)) {
+ for (id, text) in ENGLISH.messages() {
+ f(id, text);
+ }
+}
pub fn format(id: &str, args: &[(&str, &str)]) -> String {
CURRENT.with(|current| current.get().format(id, args))
}
diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rs
index 90ebe494c3..fa3d1a1c15 100644
--- a/crates/ui-egui/src/keymap.rs
+++ b/crates/ui-egui/src/keymap.rs
@@ -436,9 +436,11 @@ pub fn reset(app: &mut SolveApp, id: Option<&str>) {
/// reset; a key another command uses is reported and taken over only on request.
pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) {
let ctx = ui.ctx().clone();
+ let filtering = crate::prefs_search::querying(ui);
// Keep a pending chord until it has settled and all keys are released. Modifier-only
// input never starts the timer, so modifiers can be assembled at the user's own pace.
- if let Some(id) = app.keymap.capturing.clone() {
+ // A Preferences search is using the keyboard; don't swallow those keys to finish a capture.
+ if !filtering && let Some(id) = app.keymap.capturing.clone() {
match ctx.input(|i| app.keymap.recorder.update(i)) {
Recording::Waiting => {
if app.keymap.recorder.key.is_some() {
@@ -479,83 +481,95 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) {
}
let mut action: Option<(String, &str)> = None;
ui_kit::scope(ui, |ui| {
- let actions = [
- ui_kit::SearchAction { label: app.tr_label("Reset All"), icon: None, visible: !app.keymap.read_only, tooltip: None },
- ui_kit::SearchAction { label: app.tr_label("Import…"), icon: Some("import_tray"), visible: !app.keymap.read_only, tooltip: None },
- ui_kit::SearchAction {
- label: app.tr_label("Export…"),
- icon: Some("export_tray"),
- visible: true,
- tooltip: Some(app.tr_label("Keys, S box favourites and the toolbar, as a file")),
- },
- ];
- let (filter, toolbar_action) = ui_kit::search_actions_row(
- ui,
- egui::Id::new("sc_keymap_filter"),
- &mut app.keymap.filter,
- crate::i18n::tr_label("Filter commands or keys"),
- &actions,
- );
- crate::scenario::publish_target("keymap:filter", filter.rect);
- crate::scenario::publish_handle("shortcut:filter", filter.rect.center());
- if filter.clicked() {
- action = Some((String::new(), "cancel"));
- }
- if let Some(index) = toolbar_action {
- action = Some((
- String::new(),
- match index {
- 0 => "reset_all",
- 1 => "import",
- _ => "export",
+ if !filtering {
+ let actions = [
+ ui_kit::SearchAction { label: app.tr_label("Reset All"), icon: None, visible: !app.keymap.read_only, tooltip: None },
+ ui_kit::SearchAction { label: app.tr_label("Import…"), icon: Some("import_tray"), visible: !app.keymap.read_only, tooltip: None },
+ ui_kit::SearchAction {
+ label: app.tr_label("Export…"),
+ icon: Some("export_tray"),
+ visible: true,
+ tooltip: Some(app.tr_label("Keys, S box favourites and the toolbar, as a file")),
},
- ));
- }
- if let Some(m) = &app.keymap.message {
- ui_kit::text(ui, m, ui_kit::Text::Report("keymap_message", true));
- }
- if let Some((id, key, _)) = app.keymap.conflict.clone() {
- ui.horizontal_wrapped(|ui| {
- let replace = ui_kit::button(ui, crate::i18n::format("keymap.use_anyway", &[("key", &display(&key))]), ui_kit::Button::Normal);
- crate::scenario::publish_target("keymap:replace", replace.rect);
- if replace.clicked() {
- action = Some((format!("{id}\n{key}"), "replace"));
- }
- if ui_kit::button(ui, app.tr_label("Cancel"), ui_kit::Button::Normal).clicked() {
- action = Some((String::new(), "cancel"));
- }
- });
+ ];
+ let (filter, toolbar_action) = ui_kit::search_actions_row(
+ ui,
+ egui::Id::new("sc_keymap_filter"),
+ &mut app.keymap.filter,
+ crate::i18n::tr_label("Filter commands or keys"),
+ &actions,
+ );
+ crate::scenario::publish_target("keymap:filter", filter.rect);
+ crate::scenario::publish_handle("shortcut:filter", filter.rect.center());
+ if filter.clicked() {
+ action = Some((String::new(), "cancel"));
+ }
+ if let Some(index) = toolbar_action {
+ action = Some((
+ String::new(),
+ match index {
+ 0 => "reset_all",
+ 1 => "import",
+ _ => "export",
+ },
+ ));
+ }
+ if let Some(m) = &app.keymap.message {
+ ui_kit::text(ui, m, ui_kit::Text::Report("keymap_message", true));
+ }
+ if let Some((id, key, _)) = app.keymap.conflict.clone() {
+ ui.horizontal_wrapped(|ui| {
+ let replace = ui_kit::button(ui, crate::i18n::format("keymap.use_anyway", &[("key", &display(&key))]), ui_kit::Button::Normal);
+ crate::scenario::publish_target("keymap:replace", replace.rect);
+ if replace.clicked() {
+ action = Some((format!("{id}\n{key}"), "replace"));
+ }
+ if ui_kit::button(ui, app.tr_label("Cancel"), ui_kit::Button::Normal).clicked() {
+ action = Some((String::new(), "cancel"));
+ }
+ });
+ }
+ ui_kit::text(ui, app.tr_label("Select Other: hold the left button still on the model (or right-click › Select Other…) to list everything under the cursor; click again on the same spot to select the next thing there. Double-click the middle button to go Home (Preferences › Navigation)."), ui_kit::Text::Note("navigation"));
}
- ui_kit::text(ui, app.tr_label("Select Other: hold the left button still on the model (or right-click › Select Other…) to list everything under the cursor; click again on the same spot to select the next thing there. Double-click the middle button to go Home (Preferences › Navigation)."), ui_kit::Text::Note("navigation"));
- if !app.keymap.read_only {
+ if !filtering && !app.keymap.read_only {
ui_kit::text(ui, app.tr("ui.shortcut_capture_hint"), ui_kit::Text::Note("shortcut_capture_help"));
if app.keymap.capturing.is_some() {
let hint = ctx.input(|input| app.keymap.recorder.hint(input));
ui_kit::text(ui, app.tr(hint), ui_kit::Text::Hint("shortcut_capture_state"));
}
}
- let q = app.keymap.filter.to_lowercase();
+ let q = if filtering { app.prefs_window.filter.trim().to_lowercase() } else { app.keymap.filter.to_lowercase() };
let commands: Vec<_> = command_specs()
.into_iter()
.filter_map(|c| {
let key = effective_for_spec(app, c).unwrap_or_default();
let label = app.tr_label(c.label);
- (q.is_empty() || [c.label, c.id, key, label].iter().any(|s| s.to_lowercase().contains(&q))).then_some((c, key, label))
+ let hit = if filtering {
+ crate::prefs_search::matches_text(&q, &[c.label, c.id, key, label])
+ } else {
+ q.is_empty() || [c.label, c.id, key, label].iter().any(|s| s.to_lowercase().contains(&q))
+ };
+ hit.then_some((c, key, label))
})
.collect();
- let t = crate::theme::Tokens::get();
- let key_width = commands
- .iter()
- .map(|(_, key, _)| ui_kit::ContentWidth::button(ui, &display(key)))
- .chain(app.keymap.recorder.preview().filter(|_| app.keymap.capturing.is_some()).map(|text| ui_kit::ContentWidth::button(ui, &text)))
- .fold(ui_kit::ContentWidth::button(ui, app.tr_label("press a key…")), f32::max)
- .max(ui_kit::ContentWidth::label(ui, app.tr_label("Keyboard Shortcuts")) + t.space_8);
- let action_width = if app.keymap.read_only {
- t.control_height
- } else {
- ui_kit::ContentWidth::button(ui, app.tr_label("Clear")) + ui_kit::ContentWidth::button(ui, app.tr_label("Reset")) + t.space_4
- };
- ui_kit::settings_scroll(ui, "sc_keymap_scroll", |ui| {
+ if filtering && commands.is_empty() {
+ return;
+ }
+ let count = commands.len();
+ let shortcut_title = app.tr("prefs.shortcuts").to_string();
+ let paint = |ui: &mut egui::Ui| {
+ let t = crate::theme::Tokens::get();
+ let key_width = commands
+ .iter()
+ .map(|(_, key, _)| ui_kit::ContentWidth::button(ui, &display(key)))
+ .chain(app.keymap.recorder.preview().filter(|_| app.keymap.capturing.is_some()).map(|text| ui_kit::ContentWidth::button(ui, &text)))
+ .fold(ui_kit::ContentWidth::button(ui, app.tr_label("press a key…")), f32::max)
+ .max(ui_kit::ContentWidth::label(ui, app.tr_label("Keyboard Shortcuts")) + t.space_8);
+ let action_width = if app.keymap.read_only {
+ t.control_height
+ } else {
+ ui_kit::ContentWidth::button(ui, app.tr_label("Clear")) + ui_kit::ContentWidth::button(ui, app.tr_label("Reset")) + t.space_4
+ };
let columns = [
ui_kit::Column::new("Command", 1.5).flex().min_content_width(t.form_label_width),
ui_kit::Column::new(crate::i18n::tr("keymap.command_id"), 1.8).flex().min_content_width(t.form_label_width),
@@ -619,7 +633,12 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) {
});
}
});
- });
+ };
+ if filtering {
+ ui_kit::search_fold(ui, &shortcut_title, count, paint);
+ } else {
+ ui_kit::settings_scroll(ui, "sc_keymap_scroll", paint);
+ }
});
crate::scenario::publish_count("shortcut_recording", f64::from(app.keymap.capturing.is_some()));
if action.is_some() {
@@ -897,6 +916,17 @@ mod tests {
assert!(a.keymap.recorder.key.is_none());
}
+ #[test]
+ fn recording_a_shortcut_does_not_type_into_preferences_search() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.home.open = false;
+ crate::prefs::open_at(&mut h.app, crate::prefs::PAGE_SHORTCUTS);
+ h.app.keymap.capturing = Some("solid.extrude".into());
+ h.frames(1);
+ h.step(&json!({"text": "z"})).expect("key while recording");
+ assert!(h.app.prefs_window.filter.is_empty(), "a shortcut being recorded keeps the key");
+ }
+
#[test]
fn escape_cancels_only_recording_and_no_command_fires_during_capture() {
let mut h = crate::scenario::Harness::new();
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index e76b0d61fb..3a76f16826 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -194,6 +194,7 @@ pub(crate) mod place_gizmo;
pub(crate) mod plugins;
pub mod prefs;
pub mod prefs_notice;
+mod prefs_search;
#[cfg(test)]
mod preselect_tests;
pub mod preview;
diff --git a/crates/ui-egui/src/plugins.rs b/crates/ui-egui/src/plugins.rs
index 6624bcbcca..f017a35f4d 100644
--- a/crates/ui-egui/src/plugins.rs
+++ b/crates/ui-egui/src/plugins.rs
@@ -152,12 +152,22 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) {
ui.label(crate::i18n::tr("ui.plugins_desktop"));
return;
};
- crate::ui_kit::search_field(ui, ui.id().with("plugins_search"), &mut app.prefs_window.plugin_query, crate::i18n::tr("ui.plugins_search"));
- ui.add_space(8.0);
let path = dir.display().to_string();
- ui.add(egui::Label::new(RichText::new(crate::i18n::format("ui.plugins_note", &[("path", &path)])).size(t.font_small).color(t.text_dim)).wrap());
+ let searching = crate::prefs_search::querying(ui);
+ // The page's own box is for browsing Plugins. The dialog search is the filter while it is active.
+ if !searching {
+ crate::ui_kit::search_field(ui, ui.id().with("plugins_search"), &mut app.prefs_window.plugin_query, crate::i18n::tr("ui.plugins_search"));
+ ui.add_space(8.0);
+ }
+ if searching {
+ crate::prefs_search::begin_section(ui, crate::i18n::tr("ui.plugins"));
+ } else {
+ ui.add(
+ egui::Label::new(RichText::new(crate::i18n::format("ui.plugins_note", &[("path", &path)])).size(t.font_small).color(t.text_dim)).wrap(),
+ );
+ }
ui.add_space(8.0);
- if crate::ui_kit::button(ui, crate::i18n::tr_label("Show in folder"), crate::ui_kit::Button::Normal).clicked() {
+ if !searching && crate::ui_kit::button(ui, crate::i18n::tr_label("Show in folder"), crate::ui_kit::Button::Normal).clicked() {
// `show_in_folder` opens the parent of the path it is given, so the argument is a name
// inside the plugins directory (it need not exist).
if let Err(e) = std::fs::create_dir_all(&dir) {
@@ -169,12 +179,19 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) {
ui.add_space(8.0);
let (plugins, skipped) = scan(&dir);
let query = app.prefs_window.plugin_query.clone();
- if plugins.is_empty() {
+ if plugins.is_empty() && !searching {
ui.label(crate::i18n::tr("ui.plugins_empty"));
}
let mut shown = 0usize;
- for plugin in plugins.iter().filter(|plugin| matches_query(plugin, &query)) {
+ for plugin in plugins.iter().filter(|plugin| searching || matches_query(plugin, &query)) {
+ if searching && !crate::prefs_search::texts_hit(ui, &[&plugin.name, &plugin.id, &plugin.description, &plugin.version]) {
+ continue;
+ }
shown += 1;
+ if searching {
+ crate::prefs_search::reveal(ui);
+ crate::prefs_search::push_force(ui);
+ }
let mut on = enabled(app, &plugin.id);
ui.horizontal(|ui| {
let check = crate::ui_kit::checkbox(ui, "", &mut on);
@@ -197,11 +214,14 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) {
});
});
ui.separator();
+ if searching {
+ crate::prefs_search::pop_force(ui);
+ }
}
- if !plugins.is_empty() && shown == 0 {
+ if !searching && !plugins.is_empty() && shown == 0 {
ui.label(crate::i18n::tr("ui.plugins_none"));
}
- if query.trim().is_empty() && !skipped.is_empty() {
+ if !searching && query.trim().is_empty() && !skipped.is_empty() {
ui.add_space(6.0);
ui.label(
RichText::new(crate::i18n::format("ui.plugins_skipped", &[("count", &skipped.len().to_string())])).size(t.font_small).color(t.text_dim),
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index f5a9226019..7ca3f10f46 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -281,11 +281,129 @@ const WINDOW_PAGES: [ui_kit::WindowPage<SolveApp>; 9] = [
},
];
+fn search_header(ui: &mut egui::Ui, app: &mut SolveApp) {
+ let typed = drive_search(ui, app);
+ let (field, _) =
+ ui_kit::search_actions_row(ui, egui::Id::new("prefs_search"), &mut app.prefs_window.filter, crate::i18n::tr("prefs.search"), &[]);
+ if typed {
+ place_search_cursor(ui.ctx(), egui::Id::new("prefs_search"), app.prefs_window.filter.chars().count());
+ }
+ crate::scenario::publish_handle("prefs:search", field.rect.center());
+ if field.has_focus() {
+ crate::prefs_search::note_key_sink(ui.ctx());
+ }
+ settle_search(app);
+ crate::prefs_search::set_reveal(ui.ctx(), app.prefs_window.reveal.clone());
+ crate::prefs_search::set_force_scroll(ui.ctx(), !app.prefs_window.filter.trim().is_empty());
+ ui.add_space(Tokens::get().space_8);
+}
+
+/// Keys for the search field. Shortcut capture keeps the key for itself.
+fn drive_search(ui: &mut egui::Ui, app: &mut SolveApp) -> bool {
+ let ctx = ui.ctx().clone();
+ if crate::keymap::capturing(app) {
+ return false;
+ }
+ let id = egui::Id::new("prefs_search");
+ if ctx.input_mut(|input| input.consume_key(egui::Modifiers::COMMAND, egui::Key::F)) {
+ ctx.memory_mut(|memory| memory.request_focus(id));
+ }
+ let sink = crate::prefs_search::key_sink(&ctx);
+ let mut typed = false;
+ if !sink {
+ let modifiers = ctx.input(|input| input.modifiers);
+ if !modifiers.command && !modifiers.ctrl && !modifiers.alt {
+ let mut chars = String::new();
+ ctx.input_mut(|input| {
+ input.events.retain(|event| {
+ let egui::Event::Text(text) = event else { return true };
+ if text.chars().any(char::is_control) {
+ return true;
+ }
+ chars.push_str(text);
+ false
+ });
+ });
+ if !chars.is_empty() {
+ app.prefs_window.filter.push_str(&chars);
+ ctx.memory_mut(|memory| memory.request_focus(id));
+ typed = true;
+ }
+ }
+ }
+ let query = app.prefs_window.filter.trim().to_lowercase();
+ if query.is_empty() {
+ return typed;
+ }
+ let (nav_query, cursor, hits) = crate::prefs_search::nav(&ctx);
+ let fresh = nav_query == query;
+ let cursor = if fresh { cursor.min(hits.len().saturating_sub(1)) } else { 0 };
+ if ctx.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown)) && fresh && !hits.is_empty() {
+ crate::prefs_search::set_cursor(&ctx, (cursor + 1).min(hits.len() - 1));
+ } else if ctx.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp)) && fresh && !hits.is_empty() {
+ crate::prefs_search::set_cursor(&ctx, cursor.saturating_sub(1));
+ } else if fresh && !hits.is_empty() && ctx.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Enter)) {
+ if let Some(hit) = hits.get(cursor) {
+ open_result(app, hit.page, &hit.label);
+ ctx.memory_mut(|memory| memory.surrender_focus(id));
+ }
+ } else {
+ crate::prefs_search::set_cursor(&ctx, cursor);
+ }
+ if !app.prefs_window.filter.trim().is_empty() && ctx.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
+ app.prefs_window.filter.clear();
+ ctx.memory_mut(|memory| memory.surrender_focus(id));
+ }
+ typed
+}
+
+fn place_search_cursor(ctx: &egui::Context, id: egui::Id, chars: usize) {
+ let Some(mut state) = egui::TextEdit::load_state(ctx, id) else { return };
+ let cursor = egui::text::CCursor::new(chars);
+ state.cursor.set_char_range(Some(egui::text::CCursorRange::one(cursor)));
+ state.store(ctx, id);
+}
+
+fn open_result(app: &mut SolveApp, page: usize, label: &str) {
+ app.prefs_window.filter.clear();
+ app.prefs_window.search_from = None;
+ app.prefs_window.section = page;
+ app.prefs_window.land_on = Some(page);
+ app.prefs_window.reveal = Some(crate::prefs_search::reveal_for(page, label));
+}
+
+/// An empty field returns to the page that was up when the search started.
+fn settle_search(app: &mut SolveApp) {
+ if app.prefs_window.filter.trim().is_empty() {
+ if app.prefs_window.reveal.is_none()
+ && let Some(page) = app.prefs_window.search_from.take()
+ {
+ app.prefs_window.section = page;
+ app.prefs_window.land_on = Some(page);
+ }
+ } else if app.prefs_window.search_from.is_none() {
+ app.prefs_window.search_from = Some(app.prefs_window.section);
+ }
+}
+
+/// A page tab leaves search and shows that page on its own.
+fn clear_search(app: &mut SolveApp) {
+ app.prefs_window.filter.clear();
+ app.prefs_window.search_from = None;
+ app.prefs_window.reveal = None;
+}
+
fn window_page<const INDEX: usize>(ui: &mut egui::Ui, app: &mut SolveApp) {
if let Some(rect) = crate::scenario::rect_of("prefs:page:Sketch") {
crate::scenario::publish_target("prefs:page:Selection", rect);
}
- if app.prefs_window.section != INDEX {
+ if let Some(page) = app.prefs_window.land_on.take() {
+ if app.prefs_window.section != page {
+ crate::keymap::stop_capture(app);
+ app.keymap.read_only = false;
+ }
+ app.prefs_window.section = page;
+ } else if app.prefs_window.section != INDEX {
crate::keymap::stop_capture(app);
app.keymap.read_only = false;
app.prefs_window.section = INDEX;
@@ -899,6 +1017,14 @@ pub struct PrefsWindow {
pub(crate) plugin_query: String,
/// The followed theme file's state (#7573): its last good theme and why a read failed.
pub(crate) follow: crate::theme_files::Follow,
+ /// Filters every page. Empty leaves the selected page as it is.
+ pub filter: String,
+ /// The page on screen when the current search started. Clearing the field returns there.
+ search_from: Option<usize>,
+ /// Set when a result is chosen, so the page draw does not put the previous tab back.
+ land_on: Option<usize>,
+ /// The row to scroll to after a result is chosen.
+ reveal: Option<crate::prefs_search::Reveal>,
}
/// Following a theme file needs the file system: the desktop app only (#7573).
@@ -1588,6 +1714,11 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
open_at(app, PAGE_SHORTCUTS);
}
if !app.prefs_window.open {
+ app.prefs_window.filter.clear();
+ app.prefs_window.search_from = None;
+ app.prefs_window.land_on = None;
+ app.prefs_window.reveal = None;
+ crate::prefs_search::set_reveal(ctx, None);
app.prefs_window.snapshot = None;
// A question left up when the dialog closed is not still asked when it opens again.
app.space_mouse.restore_pending = false;
@@ -1600,6 +1731,13 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
app.prefs_window.snapshot = Some(Snapshot::take(app));
}
unfold(ctx);
+ if let Some(reveal) = &app.prefs_window.reveal
+ && crate::now_ms() > reveal.until
+ {
+ app.prefs_window.reveal = None;
+ }
+ let sink = crate::prefs_search::shift_key_sink(ctx);
+ crate::prefs_search::set_key_sink_prev(ctx, sink);
let mut button: Option<&str> = None;
let before = app.preferences.clone();
let capturing = crate::keymap::capturing(app);
@@ -1611,7 +1749,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
.actions("OK", "Cancel", Some("Apply"));
let window = if capturing { window.keep_open_on_escape() } else { window };
let mut selected = app.prefs_window.section;
- let (closed, action) = window.show_pages(ctx, &mut selected, &WINDOW_PAGES, app, |ui| {
+ let (closed, action) = window.show_pages_with_header(ctx, &mut selected, &WINDOW_PAGES, app, search_header, clear_search, |ui| {
if ui_kit::button(ui, crate::i18n::tr("ui.restore_defaults"), ui_kit::Button::Normal)
.on_hover_text(crate::i18n::tr("ui.reset_the_settings_on_this_page"))
.clicked()
@@ -1668,6 +1806,10 @@ pub(crate) fn close(app: &mut SolveApp, revert: bool) {
}
}
app.prefs_window.open = false;
+ app.prefs_window.filter.clear();
+ app.prefs_window.search_from = None;
+ app.prefs_window.land_on = None;
+ app.prefs_window.reveal = None;
app.keymap.read_only = false;
crate::keymap::stop_capture(app);
}
@@ -1683,20 +1825,47 @@ fn up_axis_changed(app: &mut SolveApp) {
}
/// One page of the dialog. Inputs share the kit's aligned rows and tokenised controls.
+/// A search draws every page and keeps the controls that match.
fn page(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {
- if app.prefs_window.section == PAGE_SHORTCUTS {
- crate::keymap::page(app, ui);
- return;
- }
- if app.prefs_window.section == PAGE_AI {
- crate::agent_chat::settings::page(app, ui);
- return;
- }
- if app.prefs_window.section == PAGE_PLUGINS {
- crate::plugins::page(app, ui);
- return;
+ let _search = crate::prefs_search::begin(ui, &app.prefs_window.filter);
+ if crate::prefs_search::querying(ui) {
+ // Paint only the pages that match. A first pass is invisible, so the 3D mouse rows and the
+ // agent list cannot draw on top of the setting that did match.
+ let mut keep = vec![false; WINDOW_PAGES.len()];
+ for (index, item) in WINDOW_PAGES.iter().enumerate() {
+ crate::prefs_search::begin_page(ui, index, crate::i18n::tr(item.label));
+ let before = crate::prefs_search::hits(ui);
+ let mut probe = crate::prefs_search::detached_child(ui, ("prefs-search-probe", index), true);
+ draw_page(app, &mut probe, index, t);
+ keep[index] = crate::prefs_search::hits(ui) > before;
+ }
+ crate::prefs_search::rewind_search_layout(ui);
+ for (index, item) in WINDOW_PAGES.iter().enumerate() {
+ if !keep.get(index).copied().unwrap_or(false) {
+ continue;
+ }
+ crate::prefs_search::begin_page(ui, index, crate::i18n::tr(item.label));
+ let before = crate::prefs_search::hits(ui);
+ let mut child = crate::prefs_search::detached_child(ui, ("prefs-search-page", index), false);
+ draw_page(app, &mut child, index, t);
+ crate::prefs_search::commit_search_child(ui, &child, before);
+ }
+ if crate::prefs_search::hits(ui) == 0 {
+ ui.label(egui::RichText::new(crate::i18n::tr("prefs.search_empty")).size(t.font_body).color(t.form_dim));
+ }
+ } else {
+ let label = WINDOW_PAGES.get(app.prefs_window.section).map(|item| crate::i18n::tr(item.label)).unwrap_or("");
+ crate::prefs_search::begin_page(ui, app.prefs_window.section, label);
+ draw_page(app, ui, app.prefs_window.section, t);
}
- match app.prefs_window.section {
+ crate::prefs_search::store_nav(ui);
+}
+
+fn draw_page(app: &mut SolveApp, ui: &mut egui::Ui, index: usize, t: &Tokens) {
+ match index {
+ PAGE_SHORTCUTS => crate::keymap::page(app, ui),
+ PAGE_AI => crate::agent_chat::settings::page(app, ui),
+ PAGE_PLUGINS => crate::plugins::page(app, ui),
PAGE_GENERAL => general::show(app, ui),
PAGE_INTERFACE => interface::interface(app, ui, t),
PAGE_DESIGN => design::show(app, ui),
diff --git a/crates/ui-egui/src/prefs_search.rs b/crates/ui-egui/src/prefs_search.rs
new file mode 100644
index 0000000000..77bc492430
--- /dev/null
+++ b/crates/ui-egui/src/prefs_search.rs
@@ -0,0 +1,778 @@
+//! Search across Preferences. The field is the Keyboard Shortcuts magnifier. A match is the
+//! control's own label, its section, its page, or the value a dropdown is showing, scored the
+//! same way as command search. English counts too, from the message catalog, so a new setting
+//! is found by being drawn — nothing is registered for search.
+
+use std::collections::{HashMap, HashSet};
+
+use egui::{Context, Id, Pos2, Rect, Response, RichText, Sense, Ui, UiBuilder, Vec2, vec2};
+
+use crate::theme::Tokens;
+
+const STATE: &str = "prefs_search_state";
+const SCROLL: &str = "prefs_search_force_scroll";
+const NAV: &str = "prefs_search_nav";
+const SINK_NOW: &str = "prefs_search_key_sink";
+const SINK_PREV: &str = "prefs_search_key_sink_prev";
+const REVEAL_ID: &str = "prefs_search_reveal";
+
+/// How long an opened result stays outlined, in milliseconds.
+const REVEAL_MS: f64 = 900.0;
+
+/// One keyboard-reachable match from the last finished pass.
+#[derive(Clone)]
+pub(crate) struct NavHit {
+ pub page: usize,
+ pub label: String,
+}
+
+#[derive(Clone)]
+struct PaintedHit {
+ page: usize,
+ label: String,
+}
+
+#[derive(Clone, Default)]
+struct NavStore {
+ query: String,
+ cursor: usize,
+ hits: Vec<NavHit>,
+}
+
+/// The row to scroll to and outline after a result is chosen.
+#[derive(Clone)]
+pub(crate) struct Reveal {
+ pub page: usize,
+ pub label: String,
+ pub until: f64,
+}
+
+#[derive(Clone, Default)]
+struct State {
+ live: bool,
+ query: String,
+ page: String,
+ page_shown: bool,
+ section: String,
+ section_matches: bool,
+ section_shown: String,
+ block_matches: bool,
+ force: u32,
+ /// Set while a matching row draws, so its own slider or buttons stay visible.
+ passthrough: u32,
+ /// A heading matched, so the controls under it stay visible until the next heading.
+ heading_open: bool,
+ hiding: u32,
+ key: String,
+ hits: u32,
+ page_index: usize,
+ /// Rows whose own text matched, in the order they were drawn this pass.
+ nav: Vec<PaintedHit>,
+ dirty: bool,
+ child_matched: bool,
+ memory_query: String,
+ extras: HashMap<String, String>,
+ open_blocks: HashSet<String>,
+ seen_blocks: HashSet<String>,
+}
+
+/// Held until the preferences body finishes. A dropdown value learned while a row was hidden
+/// asks egui to draw the body again in this frame, so the match appears at once.
+pub(crate) struct SearchFrame {
+ ctx: Context,
+}
+
+impl Drop for SearchFrame {
+ fn drop(&mut self) {
+ if finish(&self.ctx) {
+ self.ctx.request_discard("preferences search");
+ }
+ }
+}
+
+/// Start a pass over the preferences body. An empty filter leaves every control drawn.
+pub(crate) fn begin(ui: &Ui, filter: &str) -> SearchFrame {
+ let query: String = filter.trim().chars().take(256).collect::<String>().to_lowercase();
+ ui.ctx().data_mut(|data| {
+ let state = data.get_temp_mut_or_insert_with(Id::new(STATE), State::default);
+ let changed = state.memory_query != query;
+ if changed {
+ state.memory_query = query.clone();
+ state.open_blocks.clear();
+ state.seen_blocks.clear();
+ }
+ state.live = true;
+ state.query = query;
+ state.page.clear();
+ state.page_shown = false;
+ state.section.clear();
+ state.section_matches = false;
+ state.section_shown.clear();
+ state.block_matches = false;
+ state.force = 0;
+ state.passthrough = 0;
+ state.heading_open = false;
+ state.hiding = 0;
+ state.key.clear();
+ state.hits = 0;
+ state.nav.clear();
+ state.dirty = false;
+ state.child_matched = false;
+ });
+ SearchFrame { ctx: ui.ctx().clone() }
+}
+
+fn finish(ctx: &Context) -> bool {
+ let mut dirty = false;
+ ctx.data_mut(|data| {
+ let state = data.get_temp_mut_or_default::<State>(Id::new(STATE));
+ dirty = state.live && state.dirty;
+ state.live = false;
+ });
+ dirty
+}
+
+fn with<R>(ui: &Ui, f: impl FnOnce(&mut State) -> R) -> Option<R> {
+ let mut out = None;
+ ui.ctx().data_mut(|data| {
+ let state = data.get_temp_mut_or_default::<State>(Id::new(STATE));
+ if state.live {
+ out = Some(f(state));
+ }
+ });
+ out
+}
+
+pub(crate) fn querying(ui: &Ui) -> bool {
+ with(ui, |state| !state.query.is_empty()).unwrap_or(false)
+}
+
+pub(crate) fn hits(ui: &Ui) -> u32 {
+ with(ui, |state| state.hits).unwrap_or(0)
+}
+
+pub(crate) fn query(ui: &Ui) -> String {
+ with(ui, |state| state.query.clone()).unwrap_or_default()
+}
+
+/// A child that does not move the parent until [`commit_search_child`] says this group matched.
+/// An invisible child only counts hits, so a miss cannot paint over the setting that matched.
+pub(crate) fn detached_child(ui: &mut Ui, salt: impl std::hash::Hash + std::fmt::Debug, invisible: bool) -> Ui {
+ let mut builder = UiBuilder::new().id_salt(salt).max_rect(ui.available_rect_before_wrap()).layout(egui::Layout::top_down(egui::Align::Min));
+ if invisible {
+ builder = builder.invisible();
+ }
+ ui.new_child(builder)
+}
+
+/// Keep the child's layout only when it found something. An empty page or section leaves no gap.
+pub(crate) fn commit_search_child(ui: &mut Ui, child: &Ui, before: u32) {
+ if hits(ui) > before {
+ place_search_child(ui, child);
+ }
+}
+
+/// The group is already known to match. Keep whatever it drew.
+pub(crate) fn place_search_child(ui: &mut Ui, child: &Ui) {
+ let rect = child.min_rect();
+ if rect.height().is_finite() && rect.height() > 0.0 && rect.width().is_finite() {
+ ui.advance_cursor_after_rect(rect);
+ }
+}
+
+pub(crate) struct SearchLayoutMark {
+ page_shown: bool,
+ section_shown: String,
+ hits: u32,
+ heading_open: bool,
+ child_matched: bool,
+}
+
+pub(crate) fn search_layout_mark(ui: &Ui) -> SearchLayoutMark {
+ with(ui, |state| SearchLayoutMark {
+ page_shown: state.page_shown,
+ section_shown: state.section_shown.clone(),
+ hits: state.hits,
+ heading_open: state.heading_open,
+ child_matched: state.child_matched,
+ })
+ .unwrap_or(SearchLayoutMark { page_shown: false, section_shown: String::new(), hits: 0, heading_open: false, child_matched: false })
+}
+
+pub(crate) fn restore_search_layout(ui: &Ui, mark: SearchLayoutMark) {
+ with(ui, |state| {
+ state.page_shown = mark.page_shown;
+ state.section_shown = mark.section_shown;
+ state.hits = mark.hits;
+ state.heading_open = mark.heading_open;
+ state.child_matched = mark.child_matched;
+ });
+}
+
+/// Forget the headings counted while every page was probed, and count the visible pass again.
+/// Dropdown values learned on the probe stay, so the next pass can show them.
+pub(crate) fn rewind_search_layout(ui: &Ui) {
+ with(ui, |state| {
+ state.page_shown = false;
+ state.section_shown.clear();
+ state.section_matches = false;
+ state.block_matches = false;
+ state.heading_open = false;
+ state.hits = 0;
+ state.child_matched = false;
+ });
+}
+
+pub(crate) fn shows_all(ui: &Ui) -> bool {
+ with(ui, |state| state.section_matches || state.block_matches || state.force > 0 || state.heading_open || state.passthrough > 0).unwrap_or(false)
+}
+
+/// Stray notes, figures and buttons. A matching row opts out with [`push_passthrough`].
+pub(crate) fn suppress_chrome(ui: &Ui) -> bool {
+ querying(ui) && !shows_all(ui)
+}
+
+pub(crate) fn set_heading_open(ui: &Ui, open: bool) {
+ with(ui, |state| state.heading_open = open);
+}
+
+pub(crate) fn push_passthrough(ui: &Ui) {
+ with(ui, |state| state.passthrough = state.passthrough.saturating_add(1));
+}
+
+pub(crate) fn pop_passthrough(ui: &Ui) {
+ with(ui, |state| state.passthrough = state.passthrough.saturating_sub(1));
+}
+
+pub(crate) fn set_force_scroll(ctx: &Context, on: bool) {
+ ctx.data_mut(|data| data.insert_temp(Id::new(SCROLL), on));
+}
+
+pub(crate) fn force_scroll(ctx: &Context) -> bool {
+ ctx.data(|data| data.get_temp(Id::new(SCROLL))).unwrap_or(false)
+}
+
+pub(crate) fn begin_page(ui: &Ui, index: usize, label: &str) {
+ with(ui, |state| {
+ state.page_index = index;
+ state.page = label.to_string();
+ state.page_shown = false;
+ state.section.clear();
+ state.section_matches = false;
+ state.section_shown.clear();
+ state.heading_open = false;
+ });
+}
+
+pub(crate) fn begin_section(ui: &Ui, title: &str) {
+ let matches = text_hit(ui, title);
+ with(ui, |state| {
+ state.section = title.to_string();
+ state.section_matches = matches || state.force > 0;
+ state.section_shown.clear();
+ state.heading_open = false;
+ });
+}
+
+pub(crate) struct BlockGate {
+ key: String,
+ discover: bool,
+ pub show: bool,
+}
+
+/// `Some` while a search is active. `show` draws the block; otherwise the caller runs it hidden
+/// so a dropdown value inside can still be learned.
+pub(crate) fn block_gate(ui: &Ui, label: &str, hint: Option<&str>) -> Option<BlockGate> {
+ if !querying(ui) {
+ return None;
+ }
+ let label_hit = text_hit(ui, label) || hint.is_some_and(|hint| text_hit(ui, hint));
+ with(ui, |state| {
+ let key = format!("{}\n{}\n{}", state.page, state.section, label);
+ state.child_matched = false;
+ state.key = key.clone();
+ let discover = !state.seen_blocks.contains(&key);
+ let show = state.section_matches || state.force > 0 || label_hit || state.open_blocks.contains(&key);
+ state.block_matches = state.section_matches || state.force > 0 || label_hit;
+ BlockGate { key, discover, show }
+ })
+}
+
+pub(crate) fn block_finish(ui: &Ui, gate: &BlockGate, showed: bool, hits_before: u32) {
+ with(ui, |state| {
+ let gained = state.hits > hits_before || state.child_matched;
+ state.seen_blocks.insert(gate.key.clone());
+ if showed {
+ if gained || state.block_matches {
+ state.open_blocks.insert(gate.key.clone());
+ } else if gate.discover {
+ state.open_blocks.remove(&gate.key);
+ state.dirty = true;
+ }
+ } else if gained {
+ state.open_blocks.insert(gate.key.clone());
+ state.dirty = true;
+ }
+ state.child_matched = false;
+ state.block_matches = false;
+ });
+}
+
+pub(crate) fn push_force(ui: &Ui) {
+ with(ui, |state| state.force = state.force.saturating_add(1));
+}
+
+pub(crate) fn pop_force(ui: &Ui) {
+ with(ui, |state| state.force = state.force.saturating_sub(1));
+}
+
+pub(crate) fn set_control(ui: &Ui, label: &str) {
+ with(ui, |state| state.key = format!("{}\n{}\n{}", state.page, state.section, label));
+}
+
+/// 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 {
+ let show = wanted(ui, texts);
+ if show && querying(ui) {
+ if with(ui, |state| state.hiding > 0).unwrap_or(false) {
+ with(ui, |state| state.child_matched = true);
+ } else {
+ reveal(ui);
+ }
+ }
+ show
+}
+
+fn wanted(ui: &Ui, texts: &[&str]) -> bool {
+ if !querying(ui) {
+ return true;
+ }
+ if shows_all(ui) || texts.iter().any(|text| text_hit(ui, text)) {
+ return true;
+ }
+ with(ui, |state| {
+ let key = state.key.clone();
+ extra_hit(state, &key)
+ })
+ .unwrap_or(false)
+}
+
+/// The value a dropdown is showing. Stored for this control so the next pass can match it.
+pub(crate) fn note_current(ui: &Ui, text: &str) {
+ if !querying(ui) || text.is_empty() {
+ return;
+ }
+ let clipped: String = text.chars().take(256).collect();
+ with(ui, |state| {
+ if state.key.is_empty() {
+ return;
+ }
+ let key = state.key.clone();
+ let old = state.extras.get(&key).cloned();
+ if old.as_deref() == Some(clipped.as_str()) {
+ return;
+ }
+ let was = extra_hit_text(state, old.as_deref());
+ state.extras.insert(key, clipped.clone());
+ let now = extra_hit_text(state, Some(clipped.as_str()));
+ if was != now {
+ state.child_matched = true;
+ state.dirty = true;
+ }
+ });
+}
+
+/// After a hidden run, show the control on the next pass if its value now matches.
+pub(crate) fn recheck(ui: &Ui, texts: &[&str]) {
+ if wanted(ui, texts) {
+ with(ui, |state| {
+ state.child_matched = true;
+ state.dirty = true;
+ });
+ }
+}
+
+pub(crate) fn reveal(ui: &mut Ui) {
+ let Some((page, section, draw_page, draw_section)) = with(ui, |state| {
+ if state.hiding > 0 {
+ return None;
+ }
+ let draw_page = !state.page_shown && !state.page.is_empty();
+ let draw_section = !state.section.is_empty() && state.section_shown != state.section;
+ if draw_page {
+ state.page_shown = true;
+ state.section_shown.clear();
+ }
+ if draw_section {
+ state.section_shown = state.section.clone();
+ }
+ state.hits = state.hits.saturating_add(1);
+ Some((state.page.clone(), state.section.clone(), draw_page, draw_section))
+ })
+ .flatten() else {
+ return;
+ };
+ let t = Tokens::get();
+ if draw_page {
+ ui.add_space(t.space_8);
+ ui.label(RichText::new(page).strong().size(t.font_label).color(t.form_ink));
+ }
+ if draw_section {
+ let response = ui.label(RichText::new(section.to_uppercase()).size(t.font_small).color(t.text_dim));
+ remember(ui, &section, response.rect);
+ }
+}
+
+pub(crate) fn hidden_response(ui: &mut Ui) -> Response {
+ let mut child = ui.new_child(UiBuilder::new().invisible().max_rect(Rect::from_min_size(Pos2::ZERO, vec2(1.0, 1.0))));
+ child.allocate_response(Vec2::ZERO, Sense::hover())
+}
+
+pub(crate) fn run_hidden<R>(ui: &mut Ui, salt: &str, add: impl FnOnce(&mut Ui) -> R) -> R {
+ with(ui, |state| state.hiding = state.hiding.saturating_add(1));
+ let mut child = ui.new_child(
+ UiBuilder::new()
+ .invisible()
+ .id_salt(("prefs-search-hidden", salt))
+ .max_rect(Rect::from_min_size(egui::pos2(0.0, -10_000.0), vec2(480.0, 800.0))),
+ );
+ let result = add(&mut child);
+ with(ui, |state| state.hiding = state.hiding.saturating_sub(1));
+ result
+}
+
+fn extra_hit(state: &State, key: &str) -> bool {
+ extra_hit_text(state, state.extras.get(key).map(String::as_str))
+}
+
+fn extra_hit_text(state: &State, text: Option<&str>) -> bool {
+ text.is_some_and(|text| setting_score(&state.query, text) > 0 || english_hit(&state.query, text))
+}
+
+/// Whether any of `texts` matches the current query. Does not draw a heading.
+pub(crate) fn texts_hit(ui: &Ui, texts: &[&str]) -> bool {
+ texts.iter().any(|text| text_hit(ui, text))
+}
+
+fn text_hit(ui: &Ui, text: &str) -> bool {
+ if text.is_empty() {
+ return false;
+ }
+ with(ui, |state| text_matches(&state.query, text)).unwrap_or(false)
+}
+
+fn text_matches(query: &str, text: &str) -> bool {
+ setting_score(query, text) > 0 || english_hit(query, text) || keywords(text).iter().any(|word| setting_score(query, word) > 0)
+}
+
+/// Prefix, the start of a word, or a run of at least three characters. Scattered letters are not
+/// a match: "zoom" finds "Reverse zoom direction", and "rzd" does not. Marks are ignored, so
+/// "preferences" finds "préférences".
+fn setting_score(query: &str, text: &str) -> u32 {
+ if query.chars().count() < 2 || text.is_empty() {
+ return 0;
+ }
+ let query = fold(query);
+ let text = fold(text);
+ if text.starts_with(&query) {
+ return 1000;
+ }
+ if text.split(|c: char| !c.is_alphanumeric()).any(|word| !word.is_empty() && word.starts_with(&query)) {
+ return 800;
+ }
+ if query.chars().count() >= 3 && text.contains(&query) {
+ return 600;
+ }
+ 0
+}
+
+/// Whether `query` matches any of `texts`, including the English source of a translation.
+pub(crate) fn matches_text(query: &str, texts: &[&str]) -> bool {
+ let query = query.trim().to_lowercase();
+ if query.is_empty() {
+ return true;
+ }
+ texts.iter().any(|text| text_matches(&query, text))
+}
+
+/// Words that find a setting even though they are not written on it.
+fn keywords(text: &str) -> &'static [&'static str] {
+ match fold(text).as_str() {
+ "theme" => &["dark", "light", "appearance"],
+ "anti-aliasing" | "antialiasing" => &["antialiasing", "msaa"],
+ _ => &[],
+ }
+}
+
+/// Lower case, without the marks that distinguish "é" from "e".
+fn fold(text: &str) -> String {
+ let mut out = String::with_capacity(text.len());
+ for c in text.chars() {
+ match c {
+ 'œ' | 'Œ' => out.push_str("oe"),
+ 'æ' | 'Æ' => out.push_str("ae"),
+ 'ß' => out.push_str("ss"),
+ c => out.extend(strip_mark(c).to_lowercase()),
+ }
+ }
+ out
+}
+
+fn strip_mark(c: char) -> char {
+ match c {
+ 'À'..='Å' | 'à'..='å' | 'Ā' | 'ā' | 'Ă' | 'ă' | 'Ą' | 'ą' => 'a',
+ 'Ç' | 'ç' | 'Ć' | 'ć' | 'Č' | 'č' => 'c',
+ 'È'..='Ë' | 'è'..='ë' | 'Ē' | 'ē' | 'Ĕ' | 'ĕ' | 'Ė' | 'ė' | 'Ę' | 'ę' | 'Ě' | 'ě' => 'e',
+ 'Ì'..='Ï' | 'ì'..='ï' | 'Ī' | 'ī' | 'Į' | 'į' => 'i',
+ 'Ñ' | 'ñ' | 'Ń' | 'ń' | 'Ň' | 'ň' => 'n',
+ 'Ò'..='Ö' | 'ò'..='ö' | 'Ō' | 'ō' | 'Ő' | 'ő' => 'o',
+ 'Ù'..='Ü' | 'ù'..='ü' | 'Ū' | 'ū' | 'Ů' | 'ů' | 'Ű' | 'ű' | 'Ų' | 'ų' => 'u',
+ 'Ý' | 'ý' | 'Ÿ' | 'ÿ' => 'y',
+ 'Ž' | 'ž' => 'z',
+ c => c,
+ }
+}
+
+fn english_hit(query: &str, shown: &str) -> bool {
+ use std::cell::RefCell;
+ thread_local! {
+ static MAP: RefCell<(String, HashMap<String, Vec<String>>)> = RefCell::new((String::new(), HashMap::new()));
+ }
+ MAP.with(|slot| {
+ let lang = crate::i18n::language().to_string();
+ let mut slot = slot.borrow_mut();
+ if slot.0 != lang {
+ let mut map: HashMap<String, Vec<String>> = HashMap::new();
+ let locale = crate::i18n::Locale::for_language(&lang);
+ crate::i18n::each_english_message(|id, english| {
+ if english.contains('{') {
+ return;
+ }
+ let shown = locale.text(id);
+ if shown != english {
+ map.entry(shown.to_string()).or_default().push(english.to_string());
+ }
+ });
+ *slot = (lang, map);
+ }
+ slot.1.get(shown).is_some_and(|lines| {
+ lines.iter().any(|english| setting_score(query, english) > 0 || keywords(english).iter().any(|word| setting_score(query, word) > 0))
+ })
+ })
+}
+
+/// A text field or drag value had the keyboard on the previous frame.
+pub(crate) fn shift_key_sink(ctx: &Context) -> bool {
+ let held = ctx.data(|data| data.get_temp::<bool>(Id::new(SINK_NOW))).unwrap_or(false);
+ ctx.data_mut(|data| data.insert_temp(Id::new(SINK_NOW), false));
+ held
+}
+
+pub(crate) fn key_sink(ctx: &Context) -> bool {
+ ctx.data(|data| data.get_temp::<bool>(Id::new(SINK_PREV))).unwrap_or(false)
+}
+
+pub(crate) fn note_key_sink(ctx: &Context) {
+ ctx.data_mut(|data| data.insert_temp(Id::new(SINK_NOW), true));
+}
+
+pub(crate) fn set_key_sink_prev(ctx: &Context, held: bool) {
+ ctx.data_mut(|data| data.insert_temp(Id::new(SINK_PREV), held));
+}
+
+/// The matches drawn last frame, for Up/Down and Enter before this pass rebuilds them.
+pub(crate) fn nav(ctx: &Context) -> (String, usize, Vec<NavHit>) {
+ ctx.data(|data| {
+ let store = data.get_temp::<NavStore>(Id::new(NAV)).unwrap_or_default();
+ (store.query, store.cursor, store.hits)
+ })
+}
+
+pub(crate) fn set_cursor(ctx: &Context, cursor: usize) {
+ ctx.data_mut(|data| {
+ let store = data.get_temp_mut_or_default::<NavStore>(Id::new(NAV));
+ store.cursor = cursor;
+ });
+}
+
+/// Keep this pass's matches for the next frame's keys.
+pub(crate) fn store_nav(ui: &Ui) {
+ let (query, hits) =
+ with(ui, |state| (state.query.clone(), state.nav.iter().map(|hit| NavHit { page: hit.page, label: hit.label.clone() }).collect::<Vec<_>>()))
+ .unwrap_or_default();
+ ui.ctx().data_mut(|data| {
+ let store = data.get_temp_mut_or_default::<NavStore>(Id::new(NAV));
+ store.query = query;
+ store.hits = hits;
+ if store.cursor >= store.hits.len() {
+ store.cursor = 0;
+ }
+ });
+}
+
+/// A row whose own words matched. Section titles and controls both call this once they have a rect.
+pub(crate) fn remember(ui: &mut Ui, label: &str, rect: Rect) {
+ if !ui.is_visible() || !querying(ui) || label.is_empty() || !text_hit(ui, label) {
+ return;
+ }
+ if with(ui, |state| state.hiding > 0).unwrap_or(true) {
+ return;
+ }
+ let cursor = ui.ctx().data(|data| data.get_temp::<NavStore>(Id::new(NAV)).unwrap_or_default().cursor);
+ let selected = with(ui, |state| {
+ let selected = state.nav.len() == cursor;
+ state.nav.push(PaintedHit { page: state.page_index, label: label.to_string() });
+ selected
+ })
+ .unwrap_or(false);
+ if !selected {
+ return;
+ }
+ let t = Tokens::get();
+ ui.painter().rect_stroke(rect, t.radius_sm, egui::Stroke::new(t.space_2, t.form_primary), egui::StrokeKind::Outside);
+ ui.scroll_to_rect(rect, Some(egui::Align::Center));
+ crate::scenario::publish_handle("prefs:search:current", rect.center());
+}
+
+pub(crate) fn set_reveal(ctx: &Context, reveal: Option<Reveal>) {
+ ctx.data_mut(|data| {
+ if let Some(reveal) = reveal {
+ data.insert_temp(Id::new(REVEAL_ID), reveal);
+ } else {
+ data.remove::<Reveal>(Id::new(REVEAL_ID));
+ }
+ });
+}
+
+pub(crate) fn reveal_for(page: usize, label: &str) -> Reveal {
+ Reveal { page, label: label.to_string(), until: crate::now_ms() + REVEAL_MS }
+}
+
+/// Scroll the opened setting into view and outline it until [`Reveal::until`].
+pub(crate) fn follow(ui: &Ui, label: &str, rect: Rect) {
+ let Some(reveal) = ui.data(|data| data.get_temp::<Reveal>(Id::new(REVEAL_ID))) else { return };
+ if crate::now_ms() > reveal.until || fold(label) != fold(&reveal.label) {
+ return;
+ }
+ let page = with(ui, |state| state.page_index);
+ if page.is_some_and(|page| page != reveal.page) {
+ return;
+ }
+ ui.scroll_to_rect(rect, Some(egui::Align::Center));
+ let t = Tokens::get();
+ ui.painter().rect_stroke(rect, t.radius_sm, egui::Stroke::new(t.space_2, t.form_primary), egui::StrokeKind::Outside);
+ crate::scenario::publish_handle("prefs:revealed", rect.center());
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn search_matches_a_label_a_subsequence_and_the_english_source() {
+ assert!(matches_text("zoom", &["Reverse zoom direction"]));
+ assert!(matches_text("zo", &["Reverse zoom direction"]));
+ assert!(!matches_text("rzd", &["Reverse zoom direction"]));
+ assert!(!matches_text("q", &["Units of new designs"]));
+ assert!(!matches_text("qqqq", &["Units of new designs"]));
+ let _language = crate::i18n::scope("fr");
+ assert!(matches_text("units", &["Unités des nouvelles conceptions"]));
+ assert!(matches_text("preferences", &["préférences"]));
+ assert!(matches_text("dark", &["Theme"]));
+ assert!(matches_text("antialiasing", &["Anti-aliasing"]));
+ assert!(!matches_text("dark", &["Units of new designs"]));
+ }
+
+ /// Typing focuses the field, Enter opens that setting, and Escape returns to the page
+ /// that was up when the search started. Recording a shortcut keeps the key.
+ #[test]
+ fn preferences_search_types_opens_and_returns() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.home.open = false;
+ crate::prefs::open_at(&mut h.app, crate::prefs::PAGE_GRAPHICS);
+ h.frames(2);
+ h.step(&serde_json::json!({"key": "F", "cmd": true})).expect("find");
+ h.frames(1);
+ assert!(h.ctx.memory(|memory| memory.has_focus(egui::Id::new("prefs_search"))), "Cmd+F focuses search");
+ h.step(&serde_json::json!({"text": "zo"})).expect("type");
+ h.frames(3);
+ assert!(h.widget("Reverse zoom direction").is_some(), "typed letters search from the open page");
+ assert_eq!(h.app.prefs_window.section, crate::prefs::PAGE_GRAPHICS);
+ let first = crate::scenario::handle_at("prefs:search:current");
+ h.step(&serde_json::json!({"key": "ArrowDown"})).expect("next match");
+ h.frames(1);
+ let second = crate::scenario::handle_at("prefs:search:current");
+ assert!(first.is_some() && second.is_some() && first != second, "Down moves to the next match");
+ h.step(&serde_json::json!({"key": "ArrowUp"})).expect("previous match");
+ h.frames(1);
+ assert_eq!(crate::scenario::handle_at("prefs:search:current"), first, "Up moves back");
+ h.step(&serde_json::json!({"key": "Enter"})).expect("open");
+ h.frames(2);
+ assert_eq!(h.app.prefs_window.section, crate::prefs::PAGE_NAVIGATION, "Enter opens the match's page");
+ assert!(h.app.prefs_window.filter.is_empty());
+ assert!(h.widget("Reverse zoom direction").is_some());
+ assert!(crate::scenario::handle_at("prefs:revealed").is_some(), "the opened row is highlighted");
+ crate::prefs::open_at(&mut h.app, crate::prefs::PAGE_GRAPHICS);
+ h.frames(2);
+ h.step(&serde_json::json!({"text": "zo"})).expect("search again");
+ h.frames(2);
+ h.step(&serde_json::json!({"key": "Escape"})).expect("clear");
+ h.frames(1);
+ assert!(h.app.prefs_window.filter.is_empty());
+ assert_eq!(h.app.prefs_window.section, crate::prefs::PAGE_GRAPHICS, "Escape returns to the page from before the search");
+ }
+
+ #[test]
+ fn preferences_search_filters_live_controls_across_pages() {
+ 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);
+ assert!(h.widget("Units of new designs").is_none(), "another page stays put until a search");
+ h.app.prefs_window.filter = "units".into();
+ h.frames(3);
+ assert!(h.widget("Units of new designs").is_some(), "a row is found from its label");
+ assert!(h.widget("Reverse zoom direction").is_none());
+ h.app.prefs_window.filter = "zoom".into();
+ h.frames(3);
+ assert!(h.widget("Reverse zoom direction").is_some());
+ assert!(h.widget("Units of new designs").is_none());
+ assert!(h.widget("Grid").is_none(), "a checkbox on another page stays hidden");
+ assert!(h.widget("Interface language").is_none(), "the page around a match stays hidden");
+ assert!(h.widget("Advanced").is_none(), "a folded heading is not a match");
+ let search = crate::scenario::handle_at("prefs:search").expect("search field");
+ let hit = h.widget("Reverse zoom direction").expect("zoom row");
+ let gap = hit[1] - f64::from(search.y);
+ assert!(gap < 520.0, "search results leave a {gap:.0}px gap under the field");
+ assert!(h.widget("Translation X").is_none(), "unmatched pages do not stack on the result");
+ h.app.prefs_window.filter = "extrude".into();
+ h.frames(3);
+ assert!(crate::scenario::rect_of("prefs:search:shortcuts").is_some(), "shortcut matches collapse to one row");
+ assert!(crate::scenario::rect_of("dialog:cell:Extrude").is_none(), "the shortcut list stays closed");
+ h.step(&serde_json::json!({"click": {"handle": "prefs:search:clear"}})).expect("clear");
+ h.frames(2);
+ assert!(h.app.prefs_window.filter.is_empty(), "the search X clears the field");
+ h.app.prefs_window.filter = "fusion".into();
+ h.frames(3);
+ assert!(h.widget("Mouse mapping").is_some(), "the dropdown's current value counts");
+ h.app.prefs_window.filter = "zzzz-no-setting".into();
+ h.frames(2);
+ assert!(h.widget("No matching settings").is_some());
+ h.app.prefs_window.filter = "units".into();
+ h.frames(2);
+ h.step(&serde_json::json!({"click": {"handle": "prefs:page:Design"}})).expect("design page");
+ h.frames(2);
+ assert!(h.app.prefs_window.filter.is_empty(), "a page tab clears the search");
+ assert_eq!(h.app.prefs_window.section, crate::prefs::PAGE_DESIGN);
+ assert!(h.widget("Units of new designs").is_some(), "the tab shows its own page");
+ assert!(crate::scenario::rect_of("prefs:search:shortcuts").is_none(), "shortcut matches leave with the search");
+ h.app.prefs_window.filter = "zoom".into();
+ h.frames(2);
+ h.step(&serde_json::json!({"click": {"handle": "prefs:page:Design"}})).expect("same page");
+ h.frames(2);
+ assert!(h.app.prefs_window.filter.is_empty(), "the current tab also clears the search");
+ assert!(h.widget("Reverse zoom direction").is_none());
+ assert!(h.widget("Units of new designs").is_some());
+ }
+}
diff --git a/crates/ui-egui/src/ui_kit/actions.rs b/crates/ui-egui/src/ui_kit/actions.rs
index ce757fdbf8..73d7546630 100644
--- a/crates/ui-egui/src/ui_kit/actions.rs
+++ b/crates/ui-egui/src/ui_kit/actions.rs
@@ -423,6 +423,9 @@ fn button_widget(label: egui::WidgetText, options: Button) -> egui::Button<'stat
pub fn button(ui: &mut Ui, label: impl Into<egui::WidgetText>, options: Button) -> Response {
let label = label.into();
let key = label.text().to_owned();
+ if crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, &[&key]) {
+ return crate::prefs_search::hidden_response(ui);
+ }
let response = match options {
Button::Enabled(enabled) => ui.add_enabled_ui(enabled, |ui| ui.add(button_widget(crate::i18n::tr_label(&key).into(), options))).inner,
_ => ui.add(button_widget(label, options)),
diff --git a/crates/ui-egui/src/ui_kit/checks.rs b/crates/ui-egui/src/ui_kit/checks.rs
index de96a13a10..ae109d5105 100644
--- a/crates/ui-egui/src/ui_kit/checks.rs
+++ b/crates/ui-egui/src/ui_kit/checks.rs
@@ -58,6 +58,9 @@ 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 {
+ if crate::prefs_search::querying(ui) && !crate::prefs_search::visible(ui, &[label]) {
+ return crate::prefs_search::hidden_response(ui);
+ }
let t = Tokens::get();
let font = egui::FontId::proportional(t.font_label);
let galley = ui.painter().layout_no_wrap(label.to_owned(), font.clone(), t.form_ink);
@@ -65,6 +68,8 @@ pub(crate) fn checkbox_indeterminate(ui: &mut Ui, label: &str, value: &mut bool,
let width = (t.space_14 + gap + galley.size().x).max(ui.spacing().interact_size.y).min(super::metrics::dimension(ui.available_width()));
let height = ui.spacing().interact_size.y.max(t.space_14).max(galley.size().y);
let (rect, mut response) = ui.allocate_exact_size(vec2(width, height), egui::Sense::click());
+ crate::prefs_search::remember(ui, label, rect);
+ crate::prefs_search::follow(ui, label, rect);
if response.clicked() {
*value = mixed || !*value;
response.mark_changed();
diff --git a/crates/ui-egui/src/ui_kit/choice.rs b/crates/ui-egui/src/ui_kit/choice.rs
index ec69d77cbf..b0223708aa 100644
--- a/crates/ui-egui/src/ui_kit/choice.rs
+++ b/crates/ui-egui/src/ui_kit/choice.rs
@@ -24,6 +24,12 @@ pub(crate) struct Segments<'a> {
}
pub(crate) fn segmented(ui: &mut Ui, selected: &mut usize, options: &[&str], config: Segments<'_>) -> bool {
+ if crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, options) {
+ return false;
+ }
+ if crate::prefs_search::querying(ui) && !crate::prefs_search::shows_all(ui) {
+ crate::prefs_search::reveal(ui);
+ }
let Segments { icons, workspace_accent, dense, states, compact, primary, intrinsic, proportional } = config;
let accent = crate::theme::TabAccent::current(ui.ctx());
let t = Tokens::get();
diff --git a/crates/ui-egui/src/ui_kit/fields.rs b/crates/ui-egui/src/ui_kit/fields.rs
index 5d5b391762..34f0fcc16f 100644
--- a/crates/ui-egui/src/ui_kit/fields.rs
+++ b/crates/ui-egui/src/ui_kit/fields.rs
@@ -168,6 +168,7 @@ pub(crate) fn searchable_dropdown(
custom: Option<&str>,
pending: Option<&str>,
) -> Option<String> {
+ crate::prefs_search::note_current(ui, current);
let mut chosen = None;
let row = label(ui).to_owned();
let response = egui::ComboBox::from_id_salt(id)
@@ -290,6 +291,14 @@ pub(crate) fn dropdown_menu_with_close_behavior(
close_behavior: egui::PopupCloseBehavior,
add: impl FnOnce(&mut Ui),
) -> Response {
+ crate::prefs_search::note_current(ui, current);
+ // Only a search probe may skip the real control. A dialog's first frame is not visible yet,
+ // and a stand-in there makes the next frame too short to show OK.
+ if crate::prefs_search::querying(ui)
+ && (!ui.is_visible() || (crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, &[current])))
+ {
+ return crate::prefs_search::hidden_response(ui);
+ }
let response = egui::ComboBox::from_id_salt(id)
.width(dimension(ui.available_width()))
.height(Tokens::get().space_24 * 14.0)
@@ -468,6 +477,9 @@ impl Default for Slider {
/// Native input, keyboard routing, enabled state and accessibility; one token-painted track/thumb.
/// Tokens: control_height, space_24/8/4/2, dialog_body/rule, control_fill, form_primary.
pub(crate) fn slider<T: egui::emath::Numeric>(ui: &mut Ui, value: &mut T, range: std::ops::RangeInclusive<T>, options: Slider) -> Response {
+ if crate::prefs_search::suppress_chrome(ui) {
+ return crate::prefs_search::hidden_response(ui);
+ }
// Own form styling even in callers such as the viewport menu which have no kit scope.
super::scope(ui, |ui| {
let t = Tokens::get();
@@ -498,6 +510,12 @@ pub(crate) fn slider<T: egui::emath::Numeric>(ui: &mut Ui, value: &mut T, range:
widget = widget.integer();
}
let response = ui.add(widget);
+ if ui.ctx().memory(|memory| memory.focused()).is_some_and(|id| {
+ ui.ctx().read_response(id).is_some_and(|focused| response.rect.contains(focused.rect.center()))
+ || egui::TextEdit::load_state(ui.ctx(), id).is_some()
+ }) {
+ crate::prefs_search::note_key_sink(ui.ctx());
+ }
let slider = egui::Rect::from_min_size(response.rect.min, vec2(ui.spacing().slider_width, response.rect.height()));
let mut background = ui.painter().clone();
background.set_opacity(if ui.is_visible() { 1.0 } else { 0.0 });
diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rs
index ebb3da3af2..4ea4a9fc88 100644
--- a/crates/ui-egui/src/ui_kit/gallery.rs
+++ b/crates/ui-egui/src/ui_kit/gallery.rs
@@ -1092,6 +1092,9 @@ const ELEMENTS: &[Element] = &[
element!("section", "dialog:section:Advanced", Some("dialog:section:Advanced"), |ui, _| {
section(ui, "gallery", "Advanced", false, |_| {});
}),
+ element!("search_fold", "prefs:search:shortcuts", Some("prefs:search:shortcuts"), |ui, _| {
+ search_fold(ui, "Shortcuts", 3, |_| {});
+ }),
element!("divider", "dialog:divider:gallery", None, |ui, _| {
divider(ui, "gallery");
}),
diff --git a/crates/ui-egui/src/ui_kit/layout.rs b/crates/ui-egui/src/ui_kit/layout.rs
index f9d0357e34..55700e59e5 100644
--- a/crates/ui-egui/src/ui_kit/layout.rs
+++ b/crates/ui-egui/src/ui_kit/layout.rs
@@ -53,7 +53,12 @@ pub(crate) fn label(ui: &Ui) -> &str {
pub(super) fn publish(ui: &Ui, response: &Response, kind: egui::WidgetType) {
let t = Tokens::get();
match kind {
- egui::WidgetType::TextEdit => t.input_bevel(ui, response),
+ egui::WidgetType::TextEdit => {
+ t.input_bevel(ui, response);
+ if response.has_focus() {
+ crate::prefs_search::note_key_sink(ui.ctx());
+ }
+ }
egui::WidgetType::ComboBox | egui::WidgetType::Button => t.button_bevel(ui, response, false),
_ => {}
}
@@ -94,9 +99,30 @@ pub(crate) fn choice_row(ui: &mut Ui, label: &str, id: &str, selected: &mut usiz
/// Internal form geometry for controls which need several lines (e.g. text areas).
pub(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);
+ if !crate::prefs_search::visible(ui, &[text]) {
+ let result = crate::prefs_search::run_hidden(ui, text, control);
+ crate::prefs_search::recheck(ui, &[text]);
+ return result;
+ }
+ crate::prefs_search::push_passthrough(ui);
+ passthrough = true;
+ }
+ let result = sized_row_body(ui, text, height, control);
+ if passthrough {
+ crate::prefs_search::pop_passthrough(ui);
+ }
+ result
+}
+
+fn sized_row_body<R>(ui: &mut Ui, text: &str, height: f32, control: impl FnOnce(&mut Ui) -> R) -> R {
let t = Tokens::get();
let width = dimension(ui.available_width());
let (rect, _) = ui.allocate_exact_size(vec2(width, height), egui::Sense::hover());
+ crate::prefs_search::remember(ui, text, rect);
+ crate::prefs_search::follow(ui, text, rect);
// A nested row (`" Of"`) lines up under the one above: the lookup uses the text without its
// indent and the indent stays in front of the translation. The `LABEL` tag keeps the original.
let shown = indented_label(text);
@@ -133,6 +159,9 @@ pub(super) fn sized_row<R>(ui: &mut Ui, text: &str, height: f32, control: impl F
/// row's control. It says in words what a colour or an icon shows, so colour is never the only cue.
/// Dim helper beneath a row control. Tokens: `form_icon_size, font_small, text_dim, space_8; label-column tokens`.
pub(crate) fn caption(ui: &mut Ui, aligned_to: &str, text: &str) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ return;
+ }
let t = Tokens::get();
let width = dimension(ui.available_width());
let (rect, _) = ui.allocate_exact_size(vec2(width, t.form_icon_size), egui::Sense::hover());
@@ -214,11 +243,18 @@ pub(crate) fn section_count<R>(
count: Option<impl std::fmt::Display>,
add: impl FnOnce(&mut Ui) -> R,
) -> Option<R> {
+ // A search still walks the body, so a setting inside a folded section can match, without
+ // leaving the folded heading on screen for every query.
+ if crate::prefs_search::querying(ui) && crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, &[title]) {
+ return Some(add(ui));
+ }
+ let searching = crate::prefs_search::querying(ui);
let t = Tokens::get();
ui.add_space(t.space_2);
let id = ui.make_persistent_id(id);
- let mut open = ui.ctx().data_mut(|data| data.get_persisted::<bool>(id)).unwrap_or(default_open);
+ let mut open = searching || ui.ctx().data_mut(|data| data.get_persisted::<bool>(id)).unwrap_or(default_open);
let (rect, response) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), row_height()), egui::Sense::click());
+ crate::prefs_search::follow(ui, title, rect);
if response.hovered() || response.has_focus() {
ui.painter().rect_filled(rect.shrink2(vec2(0.0, 1.0)), t.radius_sm, t.hover);
}
@@ -263,13 +299,86 @@ pub(crate) fn section_count<R>(
response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::CollapsingHeader, ui.is_enabled(), open, crate::i18n::tr_label(title)));
scenario::publish_handle(&format!("dialog:section:{title}"), response.rect.center());
scenario::publish_rect(&format!("dialog:section:{title}"), rect);
- if response.clicked() {
+ if response.clicked() && !searching {
open = !open;
}
- ui.ctx().data_mut(|data| data.insert_persisted(id, open));
+ if !searching {
+ ui.ctx().data_mut(|data| data.insert_persisted(id, open));
+ }
open.then(|| ui.push_id(id, add).inner)
}
+/// Shortcut matches during Preferences search. Closed until opened, and closed again when the
+/// query changes, so a short word does not lay out every command.
+pub(crate) fn search_fold<R>(ui: &mut Ui, title: &str, count: usize, add: impl FnOnce(&mut Ui) -> R) -> Option<R> {
+ let t = Tokens::get();
+ let id = egui::Id::new(("prefs_search_fold", title));
+ let query = crate::prefs_search::query(ui);
+ let mut open = ui.data(|data| data.get_temp::<bool>(id)).unwrap_or(false);
+ let previous = ui.data(|data| data.get_temp::<String>(id.with("query"))).unwrap_or_default();
+ if previous != query {
+ open = false;
+ }
+ crate::prefs_search::reveal(ui);
+ ui.add_space(t.space_2);
+ let (rect, response) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), row_height()), egui::Sense::click());
+ if response.hovered() || response.has_focus() {
+ ui.painter().rect_filled(rect.shrink2(vec2(0.0, 1.0)), t.radius_sm, t.hover);
+ }
+ let icon_rect = egui::Rect::from_center_size(
+ egui::pos2(rect.left() + t.form_section_icon_size / 2.0, rect.center().y),
+ vec2(t.form_section_icon_size, t.form_section_icon_size),
+ );
+ super::disclosure(ui.painter(), icon_rect.center(), open, t.form_dim);
+ let text_rect = egui::Rect::from_min_max(egui::pos2((icon_rect.right() + t.form_gap_y).min(rect.right()), rect.top()), rect.max);
+ let caption = title.to_uppercase();
+ let badge_value = count.to_string();
+ let badge_width = label_width(ui, &badge_value) + t.space_12;
+ let reserved = badge_width + t.space_12;
+ let mut format = egui::TextFormat::simple(crate::fonts::semibold(t.font_caption), t.form_dim);
+ format.extra_letter_spacing = t.font_caption * t.font_section_tracking;
+ let title_width = ui
+ .fonts_mut(|fonts| fonts.layout_job(egui::text::LayoutJob::single_section(caption.clone(), format)))
+ .size()
+ .x
+ .ceil()
+ .min((text_rect.width() - reserved).max(0.0));
+ let title_rect = egui::Rect::from_min_max(text_rect.min, egui::pos2(text_rect.left() + title_width, text_rect.bottom()));
+ paint_text(ui, title_rect, &caption, crate::fonts::semibold(t.font_caption), t.form_dim, true);
+ let mut rule_left = title_rect.right() + t.space_12;
+ let width = badge_width.min((rect.right() - rule_left).max(0.0));
+ let badge = egui::Rect::from_min_size(egui::pos2(rule_left.min(rect.right()), rect.center().y - t.space_10), vec2(width, t.space_10 * 2.0));
+ ui.painter().rect_filled(badge, t.radius_xl, t.dialog_footer);
+ ui.painter().with_clip_rect(ui.clip_rect().intersect(badge)).text(
+ badge.center(),
+ egui::Align2::CENTER_CENTER,
+ &badge_value,
+ egui::FontId::proportional(t.font_small),
+ t.form_dim,
+ );
+ rule_left = badge.right() + t.space_12;
+ if rule_left < rect.right() {
+ t.secondary_hline(ui.painter(), rule_left..=rect.right(), rect.center().y, t.dialog_rule);
+ }
+ let accessible = format!("{title} ({count})");
+ response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::CollapsingHeader, ui.is_enabled(), open, &accessible));
+ scenario::publish_rect("prefs:search:shortcuts", rect);
+ scenario::publish_handle("prefs:search:shortcuts", response.rect.center());
+ if response.clicked() {
+ open = !open;
+ }
+ ui.data_mut(|data| {
+ data.insert_temp(id.with("query"), query);
+ data.insert_temp(id, open);
+ });
+ open.then(|| {
+ crate::prefs_search::push_force(ui);
+ let result = add(ui);
+ crate::prefs_search::pop_force(ui);
+ result
+ })
+}
+
/// Picked-item list entry with a remove action. Returns that action's Response.
/// Tokens: control_height, space_8, font_label, text and icon-button tokens.
/// Picked-item row with a remove action. Tokens: `control_height, space_8, font_label, text; icon-button tokens`.
@@ -288,6 +397,9 @@ pub(crate) fn list_row(ui: &mut Ui, key: &str, text: &str) -> Response {
/// Full-width rule; Tokens: dialog_rule. Use between groups without extra padding.
/// Full-width rule without extra padding. Tokens: `dialog_rule`.
pub(crate) fn divider(ui: &mut Ui, key: &str) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ return;
+ }
let (rect, _) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), 1.0), egui::Sense::hover());
Tokens::get().secondary_hline(ui.painter(), rect.x_range(), rect.top(), Tokens::get().dialog_rule);
scenario::publish_rect(&format!("dialog:divider:{key}"), rect);
@@ -342,6 +454,22 @@ pub(crate) enum Text<'a> {
}
pub(crate) fn text(ui: &mut Ui, text: &str, style: Text<'_>) -> Response {
+ if crate::prefs_search::querying(ui) {
+ let heading = matches!(style, Text::Heading(_));
+ if heading {
+ let hit = crate::prefs_search::texts_hit(ui, &[text]);
+ crate::prefs_search::set_heading_open(ui, hit);
+ if hit {
+ crate::prefs_search::reveal(ui);
+ } else if crate::prefs_search::suppress_chrome(ui) {
+ return crate::prefs_search::hidden_response(ui);
+ }
+ } else if crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, &[text]) {
+ return crate::prefs_search::hidden_response(ui);
+ } else if crate::prefs_search::texts_hit(ui, &[text]) && !crate::prefs_search::shows_all(ui) {
+ crate::prefs_search::reveal(ui);
+ }
+ }
let t = Tokens::get();
let fixed = matches!(style, Text::Cell | Text::NameCell(_) | Text::MonoCell | Text::Value(_, _));
let ink = match style {
@@ -399,6 +527,10 @@ pub(crate) fn text(ui: &mut Ui, text: &str, style: Text<'_>) -> Response {
};
let id = format!("dialog:{kind}:{key}");
scenario::publish_rect(&id, response.rect);
+ if matches!(style, Text::Heading(_)) {
+ crate::prefs_search::remember(ui, text, response.rect);
+ crate::prefs_search::follow(ui, text, response.rect);
+ }
if !matches!(style, Text::Note(_) | Text::MonoNote(_)) {
scenario::publish_handle(&id, response.rect.center());
}
diff --git a/crates/ui-egui/src/ui_kit/panel.rs b/crates/ui-egui/src/ui_kit/panel.rs
index c75888c911..a3c0377172 100644
--- a/crates/ui-egui/src/ui_kit/panel.rs
+++ b/crates/ui-egui/src/ui_kit/panel.rs
@@ -840,18 +840,48 @@ impl<'a> Window<'a> {
}
/// Declarative page navigation: the kit owns geometry, selection and page scrolling.
+ /// Preferences uses [`Self::show_pages_with_header`]; this entry is what the page-list tests call.
+ #[cfg(test)]
pub(crate) fn show_pages<S>(
+ self,
+ ctx: &egui::Context,
+ selected: &mut usize,
+ pages: &[WindowPage<S>],
+ state: &mut S,
+ left: impl FnOnce(&mut Ui),
+ ) -> (bool, super::Action) {
+ self.show_pages_inner(ctx, selected, pages, state, None, None, left)
+ }
+
+ /// Page navigation with a strip above the page body (Preferences search).
+ /// `on_select` runs when a page tab is clicked, before that page is drawn.
+ pub(crate) fn show_pages_with_header<S>(
+ self,
+ ctx: &egui::Context,
+ selected: &mut usize,
+ pages: &[WindowPage<S>],
+ state: &mut S,
+ header: fn(&mut Ui, &mut S),
+ on_select: fn(&mut S),
+ left: impl FnOnce(&mut Ui),
+ ) -> (bool, super::Action) {
+ self.show_pages_inner(ctx, selected, pages, state, Some(header), Some(on_select), left)
+ }
+
+ fn show_pages_inner<S>(
mut self,
ctx: &egui::Context,
selected: &mut usize,
pages: &[WindowPage<S>],
state: &mut S,
+ header: Option<fn(&mut Ui, &mut S)>,
+ on_select: Option<fn(&mut S)>,
left: impl FnOnce(&mut Ui),
) -> (bool, super::Action) {
self.body_padding = false;
let rows = self.page_rows;
let padding = self.page_padding;
- self.show_with_left(ctx, true, |ui| page_list_sized(ui, selected, pages, state, rows, padding), left)
+ self.show_with_left(ctx, true, |ui| page_list_sized(ui, selected, pages, state, rows, padding, header, on_select), left)
}
/// The same bounded card frame, either movable or an input-blocking modal.
@@ -914,13 +944,25 @@ pub(crate) struct WindowPage<S> {
#[cfg(test)]
pub(super) fn page_list<S>(ui: &mut Ui, selected: &mut usize, pages: &[WindowPage<S>], state: &mut S) {
- page_list_sized(ui, selected, pages, state, 16.0, vec2(Tokens::get().space_16, Tokens::get().space_16));
+ page_list_sized(ui, selected, pages, state, 16.0, vec2(Tokens::get().space_16, Tokens::get().space_16), None, None);
}
-fn page_list_sized<S>(ui: &mut Ui, selected: &mut usize, pages: &[WindowPage<S>], state: &mut S, rows: f32, padding: egui::Vec2) {
+fn page_list_sized<S>(
+ ui: &mut Ui,
+ selected: &mut usize,
+ pages: &[WindowPage<S>],
+ state: &mut S,
+ rows: f32,
+ padding: egui::Vec2,
+ header: Option<fn(&mut Ui, &mut S)>,
+ on_select: Option<fn(&mut S)>,
+) {
let t = Tokens::get();
+ // The search strip, the gap under it, and the following item spacing sit above the page.
+ // They must not eat the rows the page already had, or the graphics checkboxes fall out of view.
+ let header_band = if header.is_some() { t.control_height + t.form_gap_y + t.space_8 } else { 0.0 };
let height = (dimension(ui.ctx().content_rect().height()) - t.form_header_height - t.form_footer_height - t.space_24 * 3.0)
- .clamp(0.0, t.control_height * rows);
+ .clamp(0.0, t.control_height * rows + header_band);
let (body, _) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), height), egui::Sense::hover());
let width = (t.form_label_width * 2.0 + t.space_24 * 2.0).min(body.width());
let nav = egui::Rect::from_min_size(body.min, vec2(width, body.height()));
@@ -944,6 +986,9 @@ fn page_list_sized<S>(ui: &mut Ui, selected: &mut usize, pages: &[WindowPage<S>]
ui.allocate_exact_size(vec2(dimension(ui.available_width()), t.control_height + t.space_4), egui::Sense::click());
if response.clicked() {
*selected = index;
+ if let Some(on_select) = on_select {
+ on_select(state);
+ }
}
let on = *selected == index;
if on || response.hovered() || response.has_focus() {
@@ -981,8 +1026,12 @@ fn page_list_sized<S>(ui: &mut Ui, selected: &mut usize, pages: &[WindowPage<S>]
let clip = egui::Rect::from_min_max(content.min, egui::pos2(body.right(), content.bottom()));
ui.set_clip_rect(ui.clip_rect().intersect(clip));
ui.spacing_mut().item_spacing.y = t.form_gap_y;
+ if let Some(header) = header {
+ header(ui, state);
+ }
+ let force_scroll = header.is_some() && crate::prefs_search::force_scroll(ui.ctx());
if let Some(page) = pages.get(*selected) {
- if page.scroll {
+ if page.scroll || force_scroll {
let scroll = super::settings_scroll(ui, ("sc_prefs_page", *selected), |ui| (page.draw)(ui, state));
scenario::publish_rect("dialog:page_body", scroll.inner_rect);
} else {
diff --git a/crates/ui-egui/src/ui_kit/preferences.rs b/crates/ui-egui/src/ui_kit/preferences.rs
index 7c27995467..83780f8e55 100644
--- a/crates/ui-egui/src/ui_kit/preferences.rs
+++ b/crates/ui-egui/src/ui_kit/preferences.rs
@@ -37,6 +37,9 @@ pub(crate) fn settings_scroll<R>(ui: &mut Ui, id: impl egui::AsIdSalt, add: impl
}
pub(crate) fn settings_heading(ui: &mut Ui, title: &str, description: &str) {
+ if crate::prefs_search::querying(ui) {
+ return;
+ }
let t = Tokens::get();
ui.scope(|ui| {
ui.spacing_mut().item_spacing.y = t.space_3;
@@ -48,7 +51,34 @@ pub(crate) fn settings_heading(ui: &mut Ui, title: &str, description: &str) {
}
/// Settings reuse the same disclosure, uppercase typography and rule as the design system.
-pub(crate) fn settings_section<R>(ui: &mut Ui, key: &str, title: &str, add: impl FnOnce(&mut Ui) -> R) -> Option<R> {
+pub(crate) fn settings_section<R>(ui: &mut Ui, key: &str, title: &str, mut add: impl FnMut(&mut Ui) -> R) -> Option<R> {
+ if crate::prefs_search::querying(ui) {
+ crate::prefs_search::begin_section(ui, title);
+ if !ui.is_visible() {
+ return Some(add(ui));
+ }
+ if crate::prefs_search::shows_all(ui) {
+ let mut child = crate::prefs_search::detached_child(ui, ("prefs-search-section", key), false);
+ let result = add(&mut child);
+ crate::prefs_search::place_search_child(ui, &child);
+ return Some(result);
+ }
+ let mark = crate::prefs_search::search_layout_mark(ui);
+ let before = crate::prefs_search::hits(ui);
+ let (gained, missed) = {
+ let mut probe = crate::prefs_search::detached_child(ui, ("prefs-search-section-probe", key), true);
+ let missed = add(&mut probe);
+ (crate::prefs_search::hits(ui) > before, missed)
+ };
+ crate::prefs_search::restore_search_layout(ui, mark);
+ if !gained {
+ return Some(missed);
+ }
+ let mut child = crate::prefs_search::detached_child(ui, ("prefs-search-section", key), false);
+ let result = add(&mut child);
+ crate::prefs_search::place_search_child(ui, &child);
+ return Some(result);
+ }
let t = Tokens::get();
ui.add_space(t.space_8);
super::section(ui, key, title, true, |ui| {
@@ -77,6 +107,10 @@ impl From<Tokens> for ThemeSwatch {
/// Controls and one explanatory specimen side by side, stacked on narrow viewports.
pub(crate) fn settings_pair<R>(ui: &mut Ui, controls: impl FnOnce(&mut Ui) -> R, preview: impl FnOnce(&mut Ui, R)) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ let _ = controls(ui);
+ return;
+ }
let t = Tokens::get();
let preview_width = t.form_card_width - t.space_8;
let gap = t.space_16 + t.space_4;
@@ -101,6 +135,14 @@ pub(crate) fn settings_pair<R>(ui: &mut Ui, controls: impl FnOnce(&mut Ui) -> R,
/// A horizontally scrollable, draggable tile rail with its import action pinned outside it.
/// The hidden scrollbar never reserves vertical space; a vertical wheel also moves the rail.
pub(crate) fn theme_rail(ui: &mut Ui, tiles: impl FnOnce(&mut Ui), import: impl FnOnce(&mut Ui)) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ ui.horizontal_wrapped(|ui| {
+ ui.spacing_mut().item_spacing.x = Tokens::get().space_8;
+ tiles(ui);
+ });
+ import(ui);
+ return;
+ }
let t = Tokens::get();
let action_width = t.form_label_width + t.space_24 + t.space_6;
let rail_width = (dimension(ui.available_width()) - action_width - t.space_8).max(0.0);
@@ -194,6 +236,9 @@ pub(super) fn theme_rail_arrow(ui: &mut Ui, rect: Rect, direction: f32, label: &
/// Dashed import tile matches the swatch tiles, while remaining permanently visible.
pub(crate) fn theme_import_tile(ui: &mut Ui, label: &str, note: &str) -> Response {
+ if crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, &[label, note]) {
+ return crate::prefs_search::hidden_response(ui);
+ }
let t = Tokens::get();
let width = t.form_label_width + t.space_24 + t.space_6;
let height = t.control_height + t.space_6 * 2.0 + t.space_4 + t.space_16 * 2.0;
@@ -229,6 +274,9 @@ pub(crate) fn theme_import_tile(ui: &mut Ui, label: &str, note: &str) -> Respons
/// Compact informational state badge for settings; never an interactive control.
pub(crate) fn settings_badge(ui: &mut Ui, text: &str, warning: bool) {
+ if crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, &[text]) {
+ return;
+ }
let t = Tokens::get();
let ink =
if warning { if crate::theme::contrast_ratio(t.warning, t.dialog_body) >= 4.5 { t.warning } else { t.form_ink } } else { t.form_success };
@@ -252,6 +300,15 @@ pub(crate) enum PreferenceFigure {
/// Reusable illustrated radio card. Width comes from the figure, and wrapping is owned by
/// the parent; labels remain accessible even when translations need an ellipsis.
pub(crate) fn option_card(ui: &mut Ui, label: &str, note: Option<&str>, selected: bool, enabled: bool, figure: PreferenceFigure) -> Response {
+ if crate::prefs_search::querying(ui) {
+ let show = match note {
+ Some(note) => crate::prefs_search::visible(ui, &[label, note]),
+ None => crate::prefs_search::visible(ui, &[label]),
+ };
+ if !show {
+ return crate::prefs_search::hidden_response(ui);
+ }
+ }
let t = Tokens::get();
let theme = matches!(figure, PreferenceFigure::Theme { .. });
let width = match figure {
@@ -502,6 +559,9 @@ pub(crate) fn layout_preview(ui: &mut Ui, state: LayoutPreview) {
}
pub(crate) fn tab_accent_strip(ui: &mut Ui) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ return;
+ }
let t = Tokens::get();
super::text(ui, crate::i18n::tr("prefs.tab_accent_note"), super::Text::Hint("tab_accent"));
let names =
@@ -584,6 +644,9 @@ pub(crate) fn settings_font_row(ui: &mut Ui, label: &str, mut add: impl FnMut(&m
/// Natural-width dim text, for inline suffixes and metadata without a full-width note row.
pub(crate) fn settings_inline_note(ui: &mut Ui, text: &str) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ return;
+ }
let t = Tokens::get();
let galley = ui.painter().layout_no_wrap(text.to_owned(), FontId::proportional(t.font_body), t.form_dim);
let (r, response) = ui.allocate_exact_size(galley.size(), Sense::hover());
@@ -593,6 +656,9 @@ pub(crate) fn settings_inline_note(ui: &mut Ui, text: &str) {
/// Framed font specimen, inheriting the chosen application font and its fallback glyphs.
pub(crate) fn font_specimen(ui: &mut Ui, text: &str) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ return;
+ }
let t = Tokens::get();
let (r, _) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), t.control_height + t.space_10), Sense::hover());
t.container_rect(ui.painter(), r, t.control_radius, t.control_fill, t.dialog_rule);
@@ -601,6 +667,9 @@ pub(crate) fn font_specimen(ui: &mut Ui, text: &str) {
/// Intrinsically sized segments, retaining the usual row label for accessibility and automation.
pub(crate) fn settings_segments(ui: &mut Ui, label: &str, selected: &mut usize, options: &[&str]) -> bool {
+ if crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, &[label]) && !crate::prefs_search::texts_hit(ui, options) {
+ return false;
+ }
let t = Tokens::get();
let widest = options.iter().map(|s| super::ContentWidth::name(ui, s)).fold(0.0, f32::max);
let width = ((widest + t.space_16) * options.len() as f32).min(dimension(ui.available_width()));
@@ -615,6 +684,9 @@ pub(crate) fn settings_segments(ui: &mut Ui, label: &str, selected: &mut usize,
}
pub(crate) fn status_palette_sample(ui: &mut Ui, mode: ColorVision) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ return;
+ }
let t = Tokens::get();
let colours = Tokens::themed(crate::theme::is_dark(), mode);
ui.horizontal_wrapped(|ui| {
diff --git a/crates/ui-egui/src/ui_kit/preferences_assistant.rs b/crates/ui-egui/src/ui_kit/preferences_assistant.rs
index 6e559b45bc..a536b6a25d 100644
--- a/crates/ui-egui/src/ui_kit/preferences_assistant.rs
+++ b/crates/ui-egui/src/ui_kit/preferences_assistant.rs
@@ -13,16 +13,35 @@ pub(crate) struct SettingsChoice<'a> {
/// Equal option cards keep the choices comparable without repeating long explanations.
pub(crate) fn settings_choices(ui: &mut Ui, choices: &[SettingsChoice<'_>], selected: &mut usize) -> bool {
+ if crate::prefs_search::querying(ui) && !crate::prefs_search::shows_all(ui) {
+ let keep: Vec<usize> = choices
+ .iter()
+ .enumerate()
+ .filter(|(_, choice)| crate::prefs_search::texts_hit(ui, &[choice.title, choice.summary]))
+ .map(|(index, _)| index)
+ .collect();
+ if keep.is_empty() {
+ return false;
+ }
+ crate::prefs_search::reveal(ui);
+ return choice_row(ui, choices, selected, &keep);
+ }
+ let keep: Vec<usize> = (0..choices.len()).collect();
+ choice_row(ui, choices, selected, &keep)
+}
+
+fn choice_row(ui: &mut Ui, choices: &[SettingsChoice<'_>], selected: &mut usize, keep: &[usize]) -> bool {
let t = Tokens::get();
- let count = choices.len().max(1);
+ let count = keep.len().max(1);
let width = ((dimension(ui.available_width()) - t.space_8 * count.saturating_sub(1) as f32) / count as f32).max(0.0);
let mut changed = false;
ui.horizontal_top(|ui| {
ui.spacing_mut().item_spacing.x = t.space_8;
- for (index, choice) in choices.iter().enumerate() {
- let response = choice_card(ui, width, choice, *selected == index);
+ for index in keep {
+ let Some(choice) = choices.get(*index) else { continue };
+ let response = choice_card(ui, width, choice, *selected == *index);
if response.clicked() {
- *selected = index;
+ *selected = *index;
changed = true;
}
}
diff --git a/crates/ui-egui/src/ui_kit/preferences_navigation.rs b/crates/ui-egui/src/ui_kit/preferences_navigation.rs
index 819c487727..7115640e57 100644
--- a/crates/ui-egui/src/ui_kit/preferences_navigation.rs
+++ b/crates/ui-egui/src/ui_kit/preferences_navigation.rs
@@ -6,6 +6,17 @@ use egui::{FontId, Rect, Sense, Stroke, Ui, pos2, vec2};
/// One mouse silhouette beside the actual mapping selector and binding legend.
/// The figure is descriptive content, not an icon asset or an application viewport.
pub(crate) fn settings_mouse_mapping(ui: &mut Ui, bindings: &[(Vec<String>, String)], mapping: impl FnOnce(&mut Ui)) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ mapping(ui);
+ for (keys, action) in bindings.iter().take(10) {
+ let chord = keys.join(" ");
+ if crate::prefs_search::texts_hit(ui, &[action, &chord]) {
+ crate::prefs_search::reveal(ui);
+ settings_gesture(ui, keys, action);
+ }
+ }
+ return;
+ }
let t = Tokens::get();
ui.horizontal_top(|ui| {
ui.spacing_mut().item_spacing.x = t.space_24 - t.space_2;
@@ -88,6 +99,9 @@ fn axis_columns(rect: Rect) -> [Rect; 5] {
}
pub(crate) fn settings_axis_header(ui: &mut Ui) {
+ if crate::prefs_search::suppress_chrome(ui) {
+ return;
+ }
let t = Tokens::get();
let (rect, _) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), t.space_24), Sense::hover());
for (column, label) in axis_columns(rect).into_iter().zip(["prefs.axis", "prefs.live_input", "", "prefs.speed", "prefs.source"]) {
@@ -105,6 +119,17 @@ pub(crate) fn settings_axis_row(
speed: impl FnOnce(&mut Ui),
source: impl FnOnce(&mut Ui),
) {
+ if crate::prefs_search::querying(ui) && crate::prefs_search::suppress_chrome(ui) && !crate::prefs_search::texts_hit(ui, &[name]) {
+ crate::prefs_search::run_hidden(ui, name, |ui| {
+ invert(ui);
+ speed(ui);
+ source(ui);
+ });
+ return;
+ }
+ if crate::prefs_search::querying(ui) {
+ crate::prefs_search::reveal(ui);
+ }
let t = Tokens::get();
let (rect, _) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), t.control_height + t.space_4), Sense::hover());
t.secondary_hline(ui.painter(), rect.x_range(), rect.bottom(), t.dialog_rule);
@@ -163,6 +188,9 @@ pub(crate) fn live_axis_bar_in(ui: &Ui, live_rect: Rect, value: f32, dead_zone:
/// Compact per-axis gain uses a consistent two-decimal specimen and the real accepted range.
pub(crate) fn settings_axis_gain(ui: &mut Ui, gain: &mut f32) -> egui::Response {
+ if crate::prefs_search::querying(ui) && (!ui.is_visible() || crate::prefs_search::suppress_chrome(ui)) {
+ return crate::prefs_search::hidden_response(ui);
+ }
let response =
ui.add(egui::DragValue::new(gain).range(0.0..=3.0).speed(0.05).suffix("×").fixed_decimals(2).custom_parser(crate::prefs::parse_number));
response.widget_info(|| {
diff --git a/crates/ui-egui/src/ui_kit/preferences_small.rs b/crates/ui-egui/src/ui_kit/preferences_small.rs
index d322d8d7a3..23d8e0827c 100644
--- a/crates/ui-egui/src/ui_kit/preferences_small.rs
+++ b/crates/ui-egui/src/ui_kit/preferences_small.rs
@@ -13,6 +13,21 @@ pub(crate) fn settings_block_hint<R>(ui: &mut Ui, label: &str, hint: &str, label
}
fn settings_block_content<R>(ui: &mut Ui, label: &str, hint: Option<&str>, label_width: f32, add: impl FnOnce(&mut Ui) -> R) -> R {
+ if let Some(gate) = crate::prefs_search::block_gate(ui, label, hint) {
+ let before = crate::prefs_search::hits(ui);
+ if !gate.show {
+ let result = crate::prefs_search::run_hidden(ui, label, add);
+ crate::prefs_search::block_finish(ui, &gate, false, before);
+ return result;
+ }
+ let result = settings_block_body(ui, label, hint, label_width, add);
+ crate::prefs_search::block_finish(ui, &gate, true, before);
+ return result;
+ }
+ settings_block_body(ui, label, hint, label_width, add)
+}
+
+fn settings_block_body<R>(ui: &mut Ui, label: &str, hint: Option<&str>, label_width: f32, add: impl FnOnce(&mut Ui) -> R) -> R {
let t = Tokens::get();
let width = super::metrics::dimension(ui.available_width());
let label_width = label_width.min(width * 0.45);
@@ -93,6 +108,9 @@ pub(crate) fn settings_autosave_timeline(ui: &mut Ui, minutes: f64) {
/// A keyboard binding table: keycaps are separate from actions and never imply fixed bindings.
pub(crate) fn settings_bindings(ui: &mut Ui, bindings: &[(&[&str], &str)]) {
+ if crate::prefs_search::querying(ui) && !crate::prefs_search::shows_all(ui) {
+ return;
+ }
let t = Tokens::get();
for (keys, action) in bindings {
let width = super::metrics::dimension(ui.available_width());
diff --git a/crates/ui-egui/src/ui_kit/reports.rs b/crates/ui-egui/src/ui_kit/reports.rs
index a67665b377..7d6cf4f59b 100644
--- a/crates/ui-egui/src/ui_kit/reports.rs
+++ b/crates/ui-egui/src/ui_kit/reports.rs
@@ -69,6 +69,13 @@ pub(crate) fn path_chip(ui: &mut Ui, path: &str, add: impl FnOnce(&mut Ui)) {
/// Empty-list dashed outline and centred caption. Retains the note rectangle.
pub(crate) fn empty_box(ui: &mut Ui, key: &str, message: &str) {
+ if crate::prefs_search::querying(ui) {
+ if crate::prefs_search::texts_hit(ui, &[message]) {
+ crate::prefs_search::reveal(ui);
+ } else if !ui.is_visible() || crate::prefs_search::suppress_chrome(ui) {
+ return;
+ }
+ }
let t = Tokens::get();
let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width().max(0.0), t.control_height * 3.0), egui::Sense::hover());
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, ui.is_enabled(), message));
diff --git a/crates/ui-egui/src/ui_kit/shortcuts.rs b/crates/ui-egui/src/ui_kit/shortcuts.rs
index 88e324f675..51d1e4b413 100644
--- a/crates/ui-egui/src/ui_kit/shortcuts.rs
+++ b/crates/ui-egui/src/ui_kit/shortcuts.rs
@@ -72,7 +72,10 @@ fn search_with_icon(ui: &mut Ui, id: egui::Id, value: &mut String, hint: &str) -
);
let icon = Rect::from_center_size(pos2(r.left() + t.space_8 + t.space_16 * 0.5, r.center().y), vec2(t.space_16, t.space_16));
icons::paint_ink(ui.painter(), icon, "zoom", t.form_dim);
- let editor = Rect::from_min_max(pos2((icon.right() + t.space_6).min(r.right()), r.top()), r.right_bottom());
+ let show_clear = !value.is_empty();
+ let clear_side = if show_clear { t.control_height } else { 0.0 };
+ let editor =
+ Rect::from_min_max(pos2((icon.right() + t.space_6).min(r.right()), r.top()), pos2((r.right() - clear_side).max(icon.right()), r.bottom()));
let response = ui
.scope_builder(egui::UiBuilder::new().max_rect(editor), |ui| {
ui.set_clip_rect(ui.clip_rect().intersect(editor));
@@ -89,7 +92,19 @@ fn search_with_icon(ui: &mut Ui, id: egui::Id, value: &mut String, hint: &str) -
)
})
.inner;
- if frame.clicked() {
+ let mut cleared = false;
+ if show_clear {
+ let clear_rect = Rect::from_center_size(pos2(r.right() - t.control_height * 0.5, r.center().y), vec2(t.control_height, t.control_height));
+ let clear = ui.push_id(id.with("clear"), |ui| super::quiet_icon_button_at(ui, clear_rect, "close", "Clear")).inner;
+ if id == egui::Id::new("prefs_search") {
+ crate::scenario::publish_handle("prefs:search:clear", clear_rect.center());
+ }
+ if clear.clicked() {
+ value.clear();
+ cleared = true;
+ }
+ }
+ if frame.clicked() && !cleared {
response.request_focus();
}
super::layout::publish(ui, &response, egui::WidgetType::TextEdit);
diff --git a/crates/ui-egui/tests/scenarios/preferences_search.json b/crates/ui-egui/tests/scenarios/preferences_search.json
new file mode 100644
index 0000000000..e72079d1ac
--- /dev/null
+++ b/crates/ui-egui/tests/scenarios/preferences_search.json
@@ -0,0 +1,13 @@
+[
+ {"note": "With Preferences open and nothing being edited, typing focuses Search settings and the letters are the query. Enter opens that setting on its own page."},
+ {"click": {"handle": "titlebar:preferences"}},
+ {"expect": {"shown": "Restore Defaults", "prefs": {"dialog": "General"}}},
+ {"text": "zo"},
+ {"frames": 3},
+ {"expect": {"shown": "Reverse zoom direction", "not_shown": "Units of new designs"}},
+ {"key": "Enter"},
+ {"frames": 2},
+ {"expect": {"shown": "Reverse zoom direction", "prefs": {"dialog": "Navigation"}}},
+ {"key": "Escape"},
+ {"expect": {"not_shown": "Restore Defaults", "prefs": {"dialog": null}}}
+]
diff --git a/docs/ui-kit.md b/docs/ui-kit.md
index be1f7db61a..fa26037310 100644
--- a/docs/ui-kit.md
+++ b/docs/ui-kit.md
@@ -121,7 +121,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
| layout: `scope`, `row` | Form styling and aligned label/control columns | `form_label_width`, `form_gap_y`, `control_*`, `font_label`, `dialog_label`, `space_4/8` |
| `caption` | Dim caption aligned beneath a control | `font_small`, `text_dim`, label-column tokens |
| `figure_rows`, `FigureSlot` | A caller-painted figure in the label column beside a stack of captioned expression fields (the Hole dialog's section); the caller gets each field's rect and hover/focus state to draw leaders and light the part it sizes. Fields keep their `dialog:<label>` handles; the block publishes `dialog:figure:<id>` and its picture `dialog:figure_picture:<id>` | `control_height`, `form_label_width`, `font_small`, `form_dim`, `space_2/4`, label gap |
-| `section`, `section_count`, `divider` | Persisted small-caps disclosure with chevron, optional count badge and trailing hairline; full-width rule | `control_height`, `dialog_rule`, `font_caption`, tracking, spacing |
+| `section`, `section_count`, `search_fold`, `divider` | Persisted small-caps disclosure with chevron, optional count badge and trailing hairline; `search_fold` is that row for shortcut matches during Preferences search, closed until opened; full-width rule | `control_height`, `dialog_rule`, `font_caption`, tracking, spacing |
| `list_row` | Picked item with a remove target | `control_height`, `font_label`, icon/spacing tokens |
| `text`, `Text` | Hint, note, report, inline or cell text; see variants below | `font_small/label`, `text/dim/error`, `control_height`, `space_4` |
| `text_lines` | Virtualized read-only licence/report lines, horizontal overflow | `font_small`, `text`, `control_height` |