diff options
author | Blaž Hrastnik | 2020-10-01 02:57:43 +0000 |
---|---|---|
committer | GitHub | 2020-10-01 02:57:43 +0000 |
commit | 1da0be0aa045a4acd0246d82bf6214f8ec651476 (patch) | |
tree | a6e1ef47c23453503d2728452b16050ae649f440 | |
parent | 592c5b0af22cc719fc1513f71706dad326ba8081 (diff) | |
parent | 13800e4dd152b018b5242de9fbdd470b23bd9c4a (diff) |
Merge pull request #1 from helix-editor/insertKeymapMove
moved insert keymap to keymap.rs
-rw-r--r-- | helix-term/src/editor.rs | 31 | ||||
-rw-r--r-- | helix-view/Cargo.toml | 1 | ||||
-rw-r--r-- | helix-view/src/commands.rs | 4 | ||||
-rw-r--r-- | helix-view/src/keymap.rs | 18 |
4 files changed, 34 insertions, 20 deletions
diff --git a/helix-term/src/editor.rs b/helix-term/src/editor.rs index a3d6a04e..2cc210f4 100644 --- a/helix-term/src/editor.rs +++ b/helix-term/src/editor.rs @@ -320,29 +320,20 @@ impl Editor { if let Some(view) = &mut self.view { match view.state.mode() { Mode::Insert => { - match event { - KeyEvent { - code: KeyCode::Esc, .. - } => commands::normal_mode(view, 1), - KeyEvent { - code: KeyCode::Backspace, - .. - } => commands::delete_char_backward(view, 1), - KeyEvent { - code: KeyCode::Delete, - .. - } => commands::delete_char_forward(view, 1), - KeyEvent { + // TODO: handle modes and sequences (`gg`) + let keys = vec![event]; + if let Some(command) = keymap[&Mode::Insert].get(&keys) { + // TODO: handle count other than 1 + command(view, 1); + } else { + if let KeyEvent { code: KeyCode::Char(c), .. - } => commands::insert_char(view, c), - KeyEvent { - code: KeyCode::Enter, - .. - } => commands::insert_char(view, '\n'), - _ => (), // skip + } = event + { + commands::insert_char(view, c); + } } - // TODO: simplistic ensure cursor in view for now view.ensure_cursor_in_view(); self.render(); diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 0d887474..d205d7ad 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [features] term = ["tui", "crossterm"] +default = ["term"] [dependencies] anyhow = "1" diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index bdfa57ec..a3906b9b 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -280,6 +280,10 @@ pub fn insert_char(view: &mut View, c: char) { // TODO: need to store into history if successful } +pub fn insert_newline(view: &mut View, _count: usize) { + insert_char(view, '\n'); +} + // TODO: handle indent-aware delete pub fn delete_char_backward(view: &mut View, count: usize) { let text = &view.state.doc.slice(..); diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index 078f2bf1..512dcbdb 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -182,6 +182,24 @@ pub fn default() -> Keymaps { code: KeyCode::Esc, modifiers: Modifiers::NONE }] => commands::normal_mode as Command, + ), + state::Mode::Insert => hashmap!( + vec![Key { + code: KeyCode::Esc, + modifiers: Modifiers::NONE + }] => commands::normal_mode as Command, + vec![Key { + code: KeyCode::Backspace, + modifiers: Modifiers::NONE + }] => commands::delete_char_backward as Command, + vec![Key { + code: KeyCode::Delete, + modifiers: Modifiers::NONE + }] => commands::delete_char_forward as Command, + vec![Key { + code: KeyCode::Enter, + modifiers: Modifiers::NONE + }] => commands::insert_newline as Command, ) ) } |