diff options
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 112 |
1 files changed, 84 insertions, 28 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5b742e43..6165c4c1 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1,11 +1,11 @@ use helix_core::{ comment, coords_at_pos, graphemes, indent::TAB_WIDTH, - movement, object, pos_at_coords, + movement::{self, Direction}, + object, pos_at_coords, regex::{self, Regex}, - register, search, selection, - state::{Direction, Granularity}, - Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection, Tendril, Transaction, + register, search, selection, Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection, + Tendril, Transaction, }; use once_cell::sync::Lazy; @@ -72,36 +72,64 @@ pub type Command = fn(cx: &mut Context); pub fn move_char_left(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .move_selection(Direction::Backward, Granularity::Character, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_horizontally( + text, + range, + Direction::Backward, + count, + false, /* extend */ + ) + }); doc.set_selection(selection); } pub fn move_char_right(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .move_selection(Direction::Forward, Granularity::Character, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_horizontally( + text, + range, + Direction::Forward, + count, + false, /* extend */ + ) + }); doc.set_selection(selection); } pub fn move_line_up(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .move_selection(Direction::Backward, Granularity::Line, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_vertically( + text, + range, + Direction::Backward, + count, + false, /* extend */ + ) + }); doc.set_selection(selection); } pub fn move_line_down(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .move_selection(Direction::Forward, Granularity::Line, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_vertically( + text, + range, + Direction::Forward, + count, + false, /* extend */ + ) + }); doc.set_selection(selection); } @@ -409,36 +437,64 @@ pub fn half_page_down(cx: &mut Context) { pub fn extend_char_left(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .extend_selection(Direction::Backward, Granularity::Character, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_horizontally( + text, + range, + Direction::Backward, + count, + true, /* extend */ + ) + }); doc.set_selection(selection); } pub fn extend_char_right(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .extend_selection(Direction::Forward, Granularity::Character, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_horizontally( + text, + range, + Direction::Forward, + count, + true, /* extend */ + ) + }); doc.set_selection(selection); } pub fn extend_line_up(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .extend_selection(Direction::Backward, Granularity::Line, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_vertically( + text, + range, + Direction::Backward, + count, + true, /* extend */ + ) + }); doc.set_selection(selection); } pub fn extend_line_down(cx: &mut Context) { let count = cx.count; let doc = cx.doc(); - let selection = doc - .state - .extend_selection(Direction::Forward, Granularity::Line, count); + let text = doc.text().slice(..); + let selection = doc.selection().transform(|range| { + movement::move_vertically( + text, + range, + Direction::Forward, + count, + true, /* extend */ + ) + }); doc.set_selection(selection); } |