From 038201647c657b2b07fa7f87aae3c609c59c77ef Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Sun, 4 Oct 2020 23:47:37 +0200 Subject: started work on goto mode --- helix-view/src/commands.rs | 22 ++++++++++++++++++++++ helix-view/src/keymap.rs | 9 +++++++++ 2 files changed, 31 insertions(+) (limited to 'helix-view') 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, ) ) } -- cgit v1.2.3-70-g09d2