use crate::keys::KeyBindings;
use crate::keys::action_shortcuts::ActionShortcuts;
pub type Hint = (String, String);
pub fn hints_for(kb: &KeyBindings, actions: &[(ActionShortcuts, &str)]) -> Vec<Hint> {
actions
.iter()
.filter_map(|(action, label)| {
kb.first_combo_for(action)
.map(|combo| (combo, label.to_string()))
})
.collect()
}
pub fn global_hints(kb: &KeyBindings) -> Vec<Hint> {
hints_for(
kb,
&[
(ActionShortcuts::SearchNotes, "search"),
(ActionShortcuts::OpenPreferences, "prefs"),
(ActionShortcuts::Quit, "quit"),
],
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn global_hints_resolve_from_default_bindings() {
let settings = crate::settings::AppSettings::default();
let hints = global_hints(&settings.key_bindings);
let labels: Vec<&str> = hints.iter().map(|(_, l)| l.as_str()).collect();
assert_eq!(labels, vec!["search", "prefs", "quit"]);
assert!(hints.iter().all(|(k, _)| !k.is_empty()));
}
#[test]
fn unbound_actions_are_dropped() {
let kb = KeyBindings::empty();
assert!(global_hints(&kb).is_empty());
}
}