diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-04-17 09:53:13 +0200 |
|---|---|---|
| committer | a-kenji <aks.kenji@protonmail.com> | 2021-04-17 15:05:34 +0200 |
| commit | e5fc158503996366b82d6f089bc6e017b08492b0 (patch) | |
| tree | 48f61f1329a5990b8ca021789e58fd16a981ba40 /src | |
| parent | Merge branch 'main' of https://github.com/zellij-org/zellij into unbind-defau... (diff) | |
| download | sl0ppij-e5fc158503996366b82d6f089bc6e017b08492b0.tar.gz sl0ppij-e5fc158503996366b82d6f089bc6e017b08492b0.tar.xz sl0ppij-e5fc158503996366b82d6f089bc6e017b08492b0.zip | |
Add Unbind for Keybindings (#241)
* will unbind all default keybindings for now
* add test for toplevel unbind
* add example/default.yaml
* add example/README.md
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/input/keybinds.rs | 9 | ||||
| -rw-r--r-- | src/common/input/unit/keybinds_test.rs | 31 |
2 files changed, 30 insertions, 10 deletions
diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index 3b57dc02..6239475e 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -19,6 +19,7 @@ pub struct ModeKeybinds(HashMap<Key, Vec<Action>>); pub struct KeybindsFromYaml { #[serde(flatten)] keybinds: HashMap<InputMode, Vec<KeyActionUnbind>>, + #[serde(default)] unbind: Unbind, } @@ -50,7 +51,7 @@ struct UnbindFromYaml { #[serde(untagged)] enum Unbind { All(bool), - // TODO: use the enum + // TODO@a-kenji: use the enum //Keys(Vec<Key>), } @@ -456,6 +457,12 @@ impl From<KeyActionUnbind> for ModeKeybinds { } } +impl Default for Unbind { + fn default() -> Unbind { + Unbind::All(false) + } +} + // The unit test location. #[cfg(test)] #[path = "./unit/keybinds_test.rs"] diff --git a/src/common/input/unit/keybinds_test.rs b/src/common/input/unit/keybinds_test.rs index 6411d017..e0d78b62 100644 --- a/src/common/input/unit/keybinds_test.rs +++ b/src/common/input/unit/keybinds_test.rs @@ -124,12 +124,25 @@ fn from_keyaction_from_yaml_to_mode_keybindings() { assert_eq!(expected, ModeKeybinds::from(keyaction)); } -//#[test] -//fn from_keybinds_from_yaml_to_keybinds(){ -//let mut keybinds_from_yaml = KeybindsFromYaml(HashMap<InputMode, Vec<KeyActionFromYaml>>); -//let actions = vec![Action::NoOp, Action::GoToTab(1), ]; -//let keyaction = KeyActionFromYaml { -//action : actions.clone(), -//key : vec![ Key::F(1), Key::Backspace , Key::Char('t'), ], -//}; -//} +#[test] +fn toplevel_unbind_unbinds_all() { + let from_yaml = KeybindsFromYaml { + unbind: Unbind::All(true), + keybinds: HashMap::new(), + }; + + let keybinds_from_yaml = Keybinds::get_default_keybinds_with_config(Some(from_yaml)); + + assert_eq!(keybinds_from_yaml, Keybinds::new()); +} + +fn no_unbind_unbinds_none() { + let from_yaml = KeybindsFromYaml { + unbind: Unbind::All(false), + keybinds: HashMap::new(), + }; + + let keybinds_from_yaml = Keybinds::get_default_keybinds_with_config(Some(from_yaml)); + + assert_eq!(keybinds_from_yaml, Keybinds::new()); +} |
