diff options
author | Jan Hrastnik | 2020-10-04 21:47:37 +0000 |
---|---|---|
committer | Jan Hrastnik | 2020-10-04 21:47:37 +0000 |
commit | 038201647c657b2b07fa7f87aae3c609c59c77ef (patch) | |
tree | 263fd1c32f17f1aef5fdcce92d7a4fc21aa895f2 /helix-view | |
parent | b7e1c0cf8253703a5eeb8453de23c8d0a6137ef1 (diff) |
started work on goto mode
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/commands.rs | 22 | ||||
-rw-r--r-- | helix-view/src/keymap.rs | 9 |
2 files changed, 31 insertions, 0 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index 6dd1101c..eb9aaf6f 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -117,6 +117,24 @@ pub fn move_next_word_end(view: &mut View, count: usize) { view.state.selection = Selection::single(pos, pos); } +pub fn move_file_start(view: &mut View, count: usize) { + // TODO: use a transaction + view.state.selection = view + .state + .move_selection(Direction::Backward, Granularity::Line, count); + + view.state.mode = Mode::Normal; +} + +pub fn move_file_end(view: &mut View, count: usize) { + // TODO: use a transaction + view.state.selection = view + .state + .move_selection(Direction::Forward, Granularity::Line, count); + + view.state.mode = Mode::Normal; +} + // avoid select by default by having a visual mode switch that makes movements into selects pub fn extend_char_left(view: &mut View, count: usize) { @@ -292,6 +310,10 @@ pub fn normal_mode(view: &mut View, _count: usize) { } } +pub fn goto_mode(view: &mut View, _count: usize) { + view.state.mode = Mode::Goto; +} + // TODO: insert means add text just before cursor, on exit we should be on the last letter. pub fn insert_char(view: &mut View, c: char) { let c = Tendril::from_char(c); diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index ef23ff2a..c93c3c1f 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -126,6 +126,7 @@ pub fn default() -> Keymaps { vec![key!('w')] => commands::move_next_word_start, vec![key!('b')] => commands::move_prev_word_start, vec![key!('e')] => commands::move_next_word_end, + vec![key!('g')] => commands::goto_mode, vec![key!('i')] => commands::insert_mode, vec![shift!('I')] => commands::prepend_to_line, vec![key!('a')] => commands::append_mode, @@ -161,6 +162,14 @@ pub fn default() -> Keymaps { code: KeyCode::Tab, modifiers: Modifiers::NONE }] => commands::insert_tab, + ), + state::Mode::Goto => hashmap!( + vec![Key { + code: KeyCode::Esc, + modifiers: Modifiers::NONE + }] => commands::normal_mode as Command, + vec![key!('g')] => commands::move_file_start as Command, + vec![key!('e')] => commands::move_file_end as Command, ) ) } |