aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/config.rs
blob: 9c962299205d5cb25542f62788f1eadd22040004 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use serde::Deserialize;

use crate::commands::Command;
use crate::keymap::Keymaps;

#[derive(Debug, PartialEq, Deserialize)]
pub struct GlobalConfig {
    pub lsp_progress: bool,
}

impl Default for GlobalConfig {
    fn default() -> Self {
        Self { lsp_progress: true }
    }
}

#[derive(Debug, Default, PartialEq, Deserialize)]
#[serde(default)]
pub struct Config {
    pub global: GlobalConfig,
    pub keys: Keymaps,
}

#[test]
fn parsing_keymaps_config_file() {
    use helix_core::hashmap;
    use helix_view::document::Mode;
    use helix_view::input::{KeyCode, KeyEvent, KeyModifiers};

    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,
                },
            })
        }
    );
}