Help: command results use the labels their menus show

Help now searches and shows a command by the label its menu draws in
the UI language, so Effect > Pathfinder > Add is found as Réunion in
French. menus::shown_label holds the menus' item-label rule, and the
menu bar and Help both call it.
This commit is contained in:
dotCooCoo committed 2026-11-17 07:44:19 -08:00
1 parent b778279d6f
commit 5a96aff5da
5 files changed
+41 -11

No files matched your search

+2 -1
View File
@@ -62,7 +62,8 @@ pub(crate) use bar::{home_key, home_showing};
use bar::{menu_body, pointer_reaches_title};
pub use context::{context_items, context_menu_body, ruler_menu_body, ruler_unit_items};
pub use entries::{
InsertableItem, MenuEntry, Row, context_entries, entry, insertable, insertable_items, menu_entries, plays_in_app, pretty_shortcut, shown_shortcut,
InsertableItem, MenuEntry, Row, context_entries, entry, insertable, insertable_items, menu_entries, plays_in_app, pretty_shortcut, shown_label,
shown_shortcut,
};
pub(crate) use invoke::graph_dialog;
#[cfg(test)]
+11 -5
View File
@@ -53,11 +53,7 @@ pub fn entry<'a>(app: &VectorcraftApp, it: &'a Item) -> Option<Entry<'a>> {
Entry::Item(Row {
command: Some((id, p)),
source: label,
label: effect_item_label(id, p)
.or_else(|| unlock_item_label(app, id, p, crate::i18n::current()))
.or_else(|| spelling_item_label(id, p))
.unwrap_or_else(|| display_label(app, id, label))
.into(),
label: shown_label(app, id, p, label).into(),
shortcut: item_shortcut(id, p),
enabled,
checked,
@@ -66,6 +62,16 @@ pub fn entry<'a>(app: &VectorcraftApp, it: &'a Item) -> Option<Entry<'a>> {
})
}
/// The label of the menu item that runs `id` with `p` and reads `label` in English, as the menus
/// draw it in the UI language: an effect's own name (Pathfinder › Add), an object's name, a
/// spelling suggestion, or [`display_label`].
pub fn shown_label(app: &VectorcraftApp, id: &str, p: &Value, label: &str) -> String {
effect_item_label(id, p)
.or_else(|| unlock_item_label(app, id, p, crate::i18n::current()))
.or_else(|| spelling_item_label(id, p))
.unwrap_or_else(|| display_label(app, id, label))
}
/// `Cmd+Shift+]` → `⇧⌘]` on macOS, `Ctrl+Shift+]` elsewhere.
pub fn pretty_shortcut(s: &str) -> String {
if s.is_empty() {
+23
View File
@@ -193,6 +193,29 @@ fn discover_command_results_follow_their_menu_label() {
assert_eq!(back["results"][index]["label"], "Hide Grid");
}
/// Help finds a command by the label its menu shows in the UI language, also where the menu names
/// an effect by its own id (Effect › Pathfinder › Add reads Réunion in French).
#[test]
fn discover_finds_commands_by_their_shown_menu_label() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let fr = crate::i18n::Lang::from_code("fr").unwrap();
let shown = crate::i18n::tr_id(fr, "pathfinder.add", "Add");
assert_ne!(shown, crate::i18n::tr(fr, "Add"));
crate::i18n::set_current(fr);
let found = app.run("help.discover.search", json!({"query": shown}));
let effect = crate::i18n::tr(fr, "Effect").to_string();
crate::i18n::set_current(crate::i18n::Lang::EN);
let found = found.unwrap();
let hits = found["results"].as_array().unwrap();
assert!(
hits.iter().any(|hit| hit["kind"] == "command"
&& hit["id"].as_str().is_some_and(|id| id.starts_with("effect."))
&& hit["label"] == shown
&& hit["path"][0] == effect),
"{found}"
);
}
#[test]
fn discover_results_show_the_current_shortcut_and_language_after_a_change() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
+3 -3
View File
@@ -79,7 +79,7 @@ fn refresh(app: &mut VectorcraftApp) {
};
hit.english_label = entry.label.clone();
hit.english_path = entry.path.clone();
hit.label = crate::i18n::tr(lang, &hit.english_label).into();
hit.label = menus::shown_label(app, &hit.id, &hit.params, &hit.english_label);
hit.path = hit.english_path.iter().map(|part| crate::i18n::tr(lang, part).into()).collect();
hit.shortcut = menus::item_shortcut(&hit.id, &hit.params).or_else(|| menus::shortcut_of(&hit.id)).unwrap_or_default().into();
}
@@ -118,13 +118,13 @@ fn search(app: &VectorcraftApp, query: &str) -> Vec<Hit> {
}
for entry in menus::menu_entries(app) {
let Some(id) = entry.command else { continue };
let label = crate::i18n::tr(lang, &entry.label);
let label = menus::shown_label(app, &id, &entry.params, &entry.label);
let path: Vec<String> = entry.path.iter().map(|part| crate::i18n::tr(lang, part).into()).collect();
if matches(&query, &format!("{} {label} {} {} {id}", entry.label, entry.path.join(" "), path.join(" "))) {
hits.push(Hit {
kind: "command",
id,
label: label.into(),
label,
path,
shortcut: entry.shortcut,
english_label: entry.label,
+2 -2
View File
@@ -3266,8 +3266,8 @@ the results. VectorCraft limits a query to 1024 characters and rejects a longer
`help.discover.search {query}` runs the same search and shows the panel. Both commands return
`{query, results: [{kind, id, label, path, shortcut}], selected}`. `kind` is `tool`, `command`, or
`tutorial`; `selected` is a zero-based result index or `null`. Search matches all the query's
words without regard to case, using translated tool and command labels as well as their English
labels, ids, and menu paths. Tutorial text remains in English. After a shortcut or the interface
words without regard to case, using translated tool labels, command labels as their menus show
them, and the English labels, ids, and menu paths. Tutorial text remains in English. After a shortcut or the interface
language changes, the kept results show the current shortcuts, labels, and menu paths, with the
query and the selected result unchanged. A command result also shows its menu item's current
label (Show Grid becomes Hide Grid), and a command that no menu lists any more, such as a removed