@@ -1,11 +1,11 @@
11use helix_core::{
22 comment, coords_at_pos, graphemes,
33 indent::TAB_WIDTH,
4− movement, object, pos_at_coords,
4+ movement::{self, Direction},
5+ object, pos_at_coords,
56 regex::{self, Regex},
6− register, search, selection,
7− state::{Direction, Granularity},
8− Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection, Tendril, Transaction,
7+ register, search, selection, Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection,
8+ Tendril, Transaction,
99};
1010
1111use once_cell::sync::Lazy;
@@ -72,36 +72,64 @@ pub type Command = fn(cx: &mut Context);
7272pub fn move_char_left(cx: &mut Context) {
7373 let count = cx.count;
7474 let doc = cx.doc();
75− let selection = doc
76− .state
77− .move_selection(Direction::Backward, Granularity::Character, count);
75+ let text = doc.text().slice(..);
76+ let selection = doc.selection().transform(|range| {
77+ movement::move_horizontally(
78+ text,
79+ range,
80+ Direction::Backward,
81+ count,
82+ false, /* extend */
83+ )
84+ });
7885 doc.set_selection(selection);
7986}
8087
8188pub fn move_char_right(cx: &mut Context) {
8289 let count = cx.count;
8390 let doc = cx.doc();
84− let selection = doc
85− .state
86− .move_selection(Direction::Forward, Granularity::Character, count);
91+ let text = doc.text().slice(..);
92+ let selection = doc.selection().transform(|range| {
93+ movement::move_horizontally(
94+ text,
95+ range,
96+ Direction::Forward,
97+ count,
98+ false, /* extend */
99+ )
100+ });
87101 doc.set_selection(selection);
88102}
89103
90104pub fn move_line_up(cx: &mut Context) {
91105 let count = cx.count;
92106 let doc = cx.doc();
93− let selection = doc
94− .state
95− .move_selection(Direction::Backward, Granularity::Line, count);
107+ let text = doc.text().slice(..);
108+ let selection = doc.selection().transform(|range| {
109+ movement::move_vertically(
110+ text,
111+ range,
112+ Direction::Backward,
113+ count,
114+ false, /* extend */
115+ )
116+ });
96117 doc.set_selection(selection);
97118}
98119
99120pub fn move_line_down(cx: &mut Context) {
100121 let count = cx.count;
101122 let doc = cx.doc();
102− let selection = doc
103− .state
104− .move_selection(Direction::Forward, Granularity::Line, count);
123+ let text = doc.text().slice(..);
124+ let selection = doc.selection().transform(|range| {
125+ movement::move_vertically(
126+ text,
127+ range,
128+ Direction::Forward,
129+ count,
130+ false, /* extend */
131+ )
132+ });
105133 doc.set_selection(selection);
106134}
107135
@@ -409,36 +437,64 @@ pub fn half_page_down(cx: &mut Context) {
409437pub fn extend_char_left(cx: &mut Context) {
410438 let count = cx.count;
411439 let doc = cx.doc();
412− let selection = doc
413− .state
414− .extend_selection(Direction::Backward, Granularity::Character, count);
440+ let text = doc.text().slice(..);
441+ let selection = doc.selection().transform(|range| {
442+ movement::move_horizontally(
443+ text,
444+ range,
445+ Direction::Backward,
446+ count,
447+ true, /* extend */
448+ )
449+ });
415450 doc.set_selection(selection);
416451}
417452
418453pub fn extend_char_right(cx: &mut Context) {
419454 let count = cx.count;
420455 let doc = cx.doc();
421− let selection = doc
422− .state
423− .extend_selection(Direction::Forward, Granularity::Character, count);
456+ let text = doc.text().slice(..);
457+ let selection = doc.selection().transform(|range| {
458+ movement::move_horizontally(
459+ text,
460+ range,
461+ Direction::Forward,
462+ count,
463+ true, /* extend */
464+ )
465+ });
424466 doc.set_selection(selection);
425467}
426468
427469pub fn extend_line_up(cx: &mut Context) {
428470 let count = cx.count;
429471 let doc = cx.doc();
430− let selection = doc
431− .state
432− .extend_selection(Direction::Backward, Granularity::Line, count);
472+ let text = doc.text().slice(..);
473+ let selection = doc.selection().transform(|range| {
474+ movement::move_vertically(
475+ text,
476+ range,
477+ Direction::Backward,
478+ count,
479+ true, /* extend */
480+ )
481+ });
433482 doc.set_selection(selection);
434483}
435484
436485pub fn extend_line_down(cx: &mut Context) {
437486 let count = cx.count;
438487 let doc = cx.doc();
439− let selection = doc
440− .state
441− .extend_selection(Direction::Forward, Granularity::Line, count);
488+ let text = doc.text().slice(..);
489+ let selection = doc.selection().transform(|range| {
490+ movement::move_vertically(
491+ text,
492+ range,
493+ Direction::Forward,
494+ count,
495+ true, /* extend */
496+ )
497+ });
442498 doc.set_selection(selection);
443499}
444500