keymap_ui: Hover tooltip for action documentation (#33862)

Closes #ISSUE

Show the documentation for an action when hovered. As a bonus, also show
the humanized command palette name!

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Ben Kunkle 2025-07-03 11:35:20 -05:00 committed by GitHub
parent 34322ef1cd
commit 4e6b7ee3ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 7 deletions

View file

@ -225,6 +225,7 @@ pub(crate) struct ActionRegistry {
all_names: Vec<&'static str>, // So we can return a static slice.
deprecated_aliases: HashMap<&'static str, &'static str>, // deprecated name -> preferred name
deprecation_messages: HashMap<&'static str, &'static str>, // action name -> deprecation message
documentation: HashMap<&'static str, &'static str>, // action name -> documentation
}
impl Default for ActionRegistry {
@ -232,6 +233,7 @@ impl Default for ActionRegistry {
let mut this = ActionRegistry {
by_name: Default::default(),
names_by_type_id: Default::default(),
documentation: Default::default(),
all_names: Default::default(),
deprecated_aliases: Default::default(),
deprecation_messages: Default::default(),
@ -327,6 +329,9 @@ impl ActionRegistry {
if let Some(deprecation_msg) = action.deprecation_message {
self.deprecation_messages.insert(name, deprecation_msg);
}
if let Some(documentation) = action.documentation {
self.documentation.insert(name, documentation);
}
}
/// Construct an action based on its name and optional JSON parameters sourced from the keymap.
@ -388,6 +393,10 @@ impl ActionRegistry {
pub fn deprecation_messages(&self) -> &HashMap<&'static str, &'static str> {
&self.deprecation_messages
}
pub fn documentation(&self) -> &HashMap<&'static str, &'static str> {
&self.documentation
}
}
/// Generate a list of all the registered actions.

View file

@ -1403,11 +1403,16 @@ impl App {
self.actions.deprecated_aliases()
}
/// Get a list of all action deprecation messages.
/// Get a map from an action name to the deprecation messages.
pub fn action_deprecation_messages(&self) -> &HashMap<&'static str, &'static str> {
self.actions.deprecation_messages()
}
/// Get a map from an action name to the documentation.
pub fn action_documentation(&self) -> &HashMap<&'static str, &'static str> {
self.actions.documentation()
}
/// Register a callback to be invoked when the application is about to quit.
/// It is not possible to cancel the quit event at this point.
pub fn on_app_quit<Fut>(