2021-06-18 00:52:41 +08:00
|
|
|
use serde::Deserialize;
|
2021-06-17 13:08:05 +02:00
|
|
|
|
2021-06-18 00:52:41 +08:00
|
|
|
use crate::commands::Command;
|
|
|
|
use crate::keymap::Keymaps;
|
2021-06-17 13:08:05 +02:00
|
|
|
|
2021-06-18 00:52:41 +08:00
|
|
|
#[derive(Debug, PartialEq, Deserialize)]
|
2021-06-18 05:57:36 +02:00
|
|
|
pub struct GlobalConfig {
|
|
|
|
pub lsp_progress: bool,
|
|
|
|
}
|
|
|
|
|
2021-06-18 15:41:49 +02:00
|
|
|
impl Default for GlobalConfig {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self { lsp_progress: true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-18 00:52:41 +08:00
|
|
|
#[derive(Debug, Default, PartialEq, Deserialize)]
|
|
|
|
#[serde(default)]
|
2021-06-17 13:08:05 +02:00
|
|
|
pub struct Config {
|
2021-06-18 05:57:36 +02:00
|
|
|
pub global: GlobalConfig,
|
2021-06-18 00:52:41 +08:00
|
|
|
pub keys: Keymaps,
|
2021-06-17 13:08:05 +02:00
|
|
|
}
|
|
|
|
|
2021-06-18 00:52:41 +08:00
|
|
|
#[test]
|
|
|
|
fn parsing_keymaps_config_file() {
|
|
|
|
use helix_core::hashmap;
|
|
|
|
use helix_view::document::Mode;
|
|
|
|
use helix_view::input::{KeyCode, KeyEvent, KeyModifiers};
|
2021-06-17 13:08:05 +02:00
|
|
|
|
2021-06-18 00:52:41 +08:00
|
|
|
let sample_keymaps = r#"
|
|
|
|
[keys.insert]
|
|
|
|
y = "move_line_down"
|
|
|
|
S-C-a = "delete_selection"
|
|
|
|
|
|
|
|
[keys.normal]
|
|
|
|
A-F12 = "move_next_word_end"
|
|
|
|
"#;
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
toml::from_str::<Config>(sample_keymaps).unwrap(),
|
|
|
|
Config {
|
|
|
|
global: Default::default(),
|
|
|
|
keys: Keymaps(hashmap! {
|
|
|
|
Mode::Insert => hashmap! {
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::Char('y'),
|
|
|
|
modifiers: KeyModifiers::NONE,
|
|
|
|
} => Command::move_line_down,
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::Char('a'),
|
|
|
|
modifiers: KeyModifiers::SHIFT | KeyModifiers::CONTROL,
|
|
|
|
} => Command::delete_selection,
|
|
|
|
},
|
|
|
|
Mode::Normal => hashmap! {
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::F(12),
|
|
|
|
modifiers: KeyModifiers::ALT,
|
|
|
|
} => Command::move_next_word_end,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
);
|
2021-06-17 13:08:05 +02:00
|
|
|
}
|