From fbed80b2f891785622ea72ae213011078877ac97 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 19:59:22 -0800 Subject: [PATCH] Command Palette: the highlighted result stays shown when a new result ranks above it When the results change under the same query and a new result pushes the highlighted one past the 50 shown results, the highlighted result now takes the last shown row, so Enter still runs it. Screen readers hear its place among every match. The saved view and saved selection catalog check also rejects two rows of one language that show the same name, also when the name holds no ASCII digits. --- crates/ui-egui/src/i18n/tests.rs | 8 +++-- crates/ui-egui/src/palette.rs | 59 ++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rs index 4311da82fd..834be07550 100644 --- a/crates/ui-egui/src/i18n/tests.rs +++ b/crates/ui-egui/src/i18n/tests.rs @@ -434,13 +434,14 @@ fn font_height_reference_labels_are_in_complete_catalogs() { } } -/// Each catalog's Saved View N and Saved Selection N rows carry the number N, so no two saved views -/// or saved selections show one name. +/// Each catalog's Saved View N and Saved Selection N rows carry the number N, and no two of a +/// catalog's saved views or saved selections show one name, whatever digits the language uses. #[test] fn numbered_saved_views_and_selections_keep_their_number() { let mut bad = vec![]; for lang in LANGUAGES.iter().filter(|lang| !lang.source.is_empty()) { for kind in ["Saved View", "Saved Selection"] { + let mut seen = std::collections::HashMap::new(); for n in 1..=25 { let source = format!("{kind} {n}"); let Some(row) = lang.catalog().plain(&source) else { continue }; @@ -448,6 +449,9 @@ fn numbered_saved_views_and_selections_keep_their_number() { if !numbers.is_empty() && numbers != [n.to_string().as_str()] { bad.push(format!("{}: {source} -> {row}", lang.code)); } + if let Some(earlier) = seen.insert(row, source.clone()) { + bad.push(format!("{}: {earlier} and {source} both show {row}", lang.code)); + } } } } diff --git a/crates/ui-egui/src/palette.rs b/crates/ui-egui/src/palette.rs index 67bd572f39..9928837ebf 100644 --- a/crates/ui-egui/src/palette.rs +++ b/crates/ui-egui/src/palette.rs @@ -588,6 +588,25 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { let entries = entries_in(ctx, crate::i18n::current(), app.services.native_menu.is_some()); let mut matches = matching(&entries, &q); let total = matches.len(); + // The highlighted result (#1757): Up and Down move it (wrapping), Page Up and Page Down move it + // by a page, the pointer over a result takes it, and a new query starts again from the first. + let sel_id = egui::Id::unique("palette-selected"); + let (mut sel, last_q, mut offset, last_view, last_id) = ctx.data(|d| d.get_temp::(sel_id)).unwrap_or_default(); + let mut view = last_view; + let new_query = last_q != q; + // A result that ranks above the highlighted one when the results change under the same query + // can push it past the last shown result; it then takes the last shown row instead, and + // `kept` holds its place among every match. + let mut kept = None; + if !new_query + && let Some(at) = matches.iter().position(|e| e.id == last_id) + && at >= MAX_RESULTS + { + let held_result = matches.remove(at); + matches.truncate(MAX_RESULTS - 1); + matches.push(held_result); + kept = Some(at); + } matches.truncate(MAX_RESULTS); let recent = recent(&entries.list, &app.ui.recent_commands); // While the Recent Commands list is open, the arrow keys and Enter go to its rows, and the @@ -595,12 +614,6 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { let list_open = recent_list_open(ctx); let mut run: Option = None; let mut history_focused = false; - // The highlighted result (#1757): Up and Down move it (wrapping), Page Up and Page Down move it - // by a page, the pointer over a result takes it, and a new query starts again from the first. - let sel_id = egui::Id::unique("palette-selected"); - let (mut sel, last_q, mut offset, last_view, last_id) = ctx.data(|d| d.get_temp::(sel_id)).unwrap_or_default(); - let mut view = last_view; - let new_query = last_q != q; // The highlight stays on its result when the results change under the same query, as when a // plug-in is installed, a shortcut changes or the language changes; it goes to the first // result when its result is gone. @@ -716,7 +729,8 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { // Screen readers stay on the field: its description names the highlighted result and // its place among every match, as the footer counts them. if let Some(e) = matches.get(sel) { - let pos = (sel + 1).to_string(); + let rank = if sel + 1 == matches.len() { kept.unwrap_or(sel) } else { sel }; + let pos = (rank + 1).to_string(); let of = total.to_string(); let said = crate::i18n::fmt(tl!("{pos} of {total}: {name}"), &[("pos", &pos), ("total", &of), ("name", &row_label(e))]); ui.ctx().accesskit_node_builder(r.id, |node| node.set_description(said)); @@ -2558,4 +2572,35 @@ mod tests { crate::i18n::set_current(Lang::EN); assert_eq!((de_listed.get(sel), &now), (Some(&id), &id), "after the language changed"); } + + /// A highlighted last shown result that a new result pushes past the limit stays shown and + /// highlighted, in the last row, so Enter still runs it; screen readers hear its place among + /// every match. + #[test] + fn the_highlighted_last_result_stays_shown_when_a_result_ranks_above_it() { + use vectorcraft_plugins::wat as tpl; + // A query no other test searches for, so the plug-in below leaves their results alone. + let mut open = Open::new("path", WINDOW); + assert!(matching(&entries(&open.ctx, Lang::EN), "path").len() > MAX_RESULTS); + open.press(egui::Key::ArrowUp, 1); + let held = |open: &Open| open.ctx.data(|d| d.get_temp::(egui::Id::unique("palette-selected"))).unwrap(); + let (sel, .., id) = held(&open); + assert_eq!(sel, MAX_RESULTS - 1); + let filter = "test.UI.palette_last-highlight-path"; + let manifest = format!(r#"{{"id":"{filter}","name":"Path Last Highlight Probe","version":"1","kind":"filter","params":{{}}}}"#); + vectorcraft_plugins::registry::install_bytes(&wat::parse_str(tpl::returning(&manifest, r#"{"objects":[]}"#)).unwrap()).unwrap(); + open.frame(vec![]); + let entries = entries(&open.ctx, Lang::EN); + let ranked: Vec<&Entry> = matching(&entries, "path"); + let nodes = open.frame(vec![]); + let (sel, .., now) = held(&open); + vectorcraft_plugins::registry::remove(filter); + let plugin = ranked.iter().position(|e| e.id == format!("plugin:{filter}")); + assert!(plugin.is_some_and(|p| p < MAX_RESULTS), "the plug-in is shown: {plugin:?}"); + assert_eq!(ranked.iter().position(|e| e.id == id), Some(MAX_RESULTS), "the plug-in pushed the highlight past the limit"); + assert_eq!((sel, &now), (MAX_RESULTS - 1, &id), "the highlight stays on its result, in the last row"); + let label = row_label(ranked[MAX_RESULTS]); + assert!(rows(&nodes).iter().any(|r| r.1 && r.0 == label), "its row is drawn and highlighted"); + assert_eq!(field_description(&nodes), format!("{} of {}: {label}", MAX_RESULTS + 1, ranked.len())); + } }