diff options
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/commands.rs | 40 | ||||
-rw-r--r-- | helix-view/src/keymap.rs | 32 |
2 files changed, 72 insertions, 0 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index 42390c23..d868a17c 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -115,6 +115,46 @@ pub fn move_next_word_end(view: &mut View, count: usize) { // 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) { + // TODO: use a transaction + let selection = view + .state + .extend_selection(Direction::Backward, Granularity::Character, count); + view.state.selection = selection; +} + +pub fn extend_char_right(view: &mut View, count: usize) { + // TODO: use a transaction + view.state.selection = + view.state + .extend_selection(Direction::Forward, Granularity::Character, count); +} + +pub fn extend_line_up(view: &mut View, count: usize) { + // TODO: use a transaction + view.state.selection = + view.state + .extend_selection(Direction::Backward, Granularity::Line, count); +} + +pub fn extend_line_down(view: &mut View, count: usize) { + // TODO: use a transaction + view.state.selection = + view.state + .extend_selection(Direction::Forward, Granularity::Line, count); +} + +pub fn delete_selection(view: &mut View, _count: usize) { + let transaction = + Transaction::change_by_selection(&view.state, |range| (range.from(), range.to(), None)); + transaction.apply(&mut view.state); +} + +pub fn change_selection(view: &mut View, count: usize) { + delete_selection(view, count); + insert_mode(view, count); +} + // insert mode: // first we calculate the correct cursors/selections // then we just append at each cursor diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index 5d9b6653..750f1a5f 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -7,7 +7,9 @@ use std::collections::HashMap; // normal = { // q = record_macro // w = (next) word +// W = next WORD // e = end of word +// E = end of WORD // r = // t = 'till char // y = yank @@ -55,6 +57,12 @@ use std::collections::HashMap; // & = align cursor // ? = extend to next given regex match (alt = to prev) // +// in kakoune these are alt-h alt-l / gh gl +// select from curs to begin end / move curs to begin end +// 0 = start of line +// ^ = start of line (first non blank char) +// $ = end of line +// // z = save selections // Z = restore selections // x = select line @@ -111,6 +119,22 @@ pub fn default() -> Keymaps { modifiers: Modifiers::NONE }] => commands::move_char_right as Command, vec![Key { + code: KeyCode::Char('H'), + modifiers: Modifiers::SHIFT + }] => commands::extend_char_left as Command, + vec![Key { + code: KeyCode::Char('J'), + modifiers: Modifiers::SHIFT + }] => commands::extend_line_down as Command, + vec![Key { + code: KeyCode::Char('K'), + modifiers: Modifiers::SHIFT + }] => commands::extend_line_up as Command, + vec![Key { + code: KeyCode::Char('L'), + modifiers: Modifiers::SHIFT + }] => commands::extend_char_right as Command, + vec![Key { code: KeyCode::Char('w'), modifiers: Modifiers::NONE }] => commands::move_next_word_start as Command, @@ -143,6 +167,14 @@ pub fn default() -> Keymaps { modifiers: Modifiers::NONE }] => commands::open_below as Command, vec![Key { + code: KeyCode::Char('d'), + modifiers: Modifiers::NONE + }] => commands::delete_selection as Command, + vec![Key { + code: KeyCode::Char('c'), + modifiers: Modifiers::NONE + }] => commands::change_selection as Command, + vec![Key { code: KeyCode::Esc, modifiers: Modifiers::NONE }] => commands::normal_mode as Command, |