Skip to main content

television/screen/
keybindings.rs

1use crate::{
2    action::{Action, Actions},
3    config::Keybindings,
4};
5
6/// Extract keys for a single action
7pub fn find_keys_for_single_action(
8    keybindings: &Keybindings,
9    target_action: &Action,
10) -> Vec<String> {
11    keybindings
12        .iter()
13        .filter_map(|(key, actions)| {
14            // Check if this actions contains the target action
15            if actions.as_slice().contains(target_action) {
16                Some(key.to_string())
17            } else {
18                None
19            }
20        })
21        .collect()
22}
23
24/// Remove all keybindings for a specific action from `KeyBindings`
25pub fn remove_action_bindings(
26    keybindings: &mut Keybindings,
27    target_action: &Actions,
28) {
29    keybindings.retain(|_, action| action != target_action);
30}