@@ -1,11 +1,11 @@
1use helix_core::{
1use helix_core::{
2 comment, coords_at_pos, graphemes,
2 comment, coords_at_pos, graphemes,
3 indent::TAB_WIDTH,
3 indent::TAB_WIDTH,
4+ movement::{self, Direction},
4− movement, object, pos_at_coords,
5+ object, pos_at_coords,
5 regex::{self, Regex},
6 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,
11use once_cell::sync::Lazy;
11use once_cell::sync::Lazy;
@@ -72,36 +72,64 @@ pub type Command = fn(cx: &mut Context);
72pub fn move_char_left(cx: &mut Context) {
72pub fn move_char_left(cx: &mut Context) {
73 let count = cx.count;
73 let count = cx.count;
74 let doc = cx.doc();
74 let doc = cx.doc();
75− let selection = doc
75+ let text = doc.text().slice(..);
76− .state
76+ let selection = doc.selection().transform(|range| {
77+ movement::move_horizontally(
77− .move_selection(Direction::Backward, Granularity::Character, count);
80+ Direction::Backward,
78 doc.set_selection(selection);
85 doc.set_selection(selection);
81pub fn move_char_right(cx: &mut Context) {
88pub fn move_char_right(cx: &mut Context) {
82 let count = cx.count;
89 let count = cx.count;
83 let doc = cx.doc();
90 let doc = cx.doc();
84− let selection = doc
91+ let text = doc.text().slice(..);
85− .state
92+ let selection = doc.selection().transform(|range| {
93+ movement::move_horizontally(
86− .move_selection(Direction::Forward, Granularity::Character, count);
96+ Direction::Forward,
87 doc.set_selection(selection);
101 doc.set_selection(selection);
90pub fn move_line_up(cx: &mut Context) {
104pub fn move_line_up(cx: &mut Context) {
91 let count = cx.count;
105 let count = cx.count;
92 let doc = cx.doc();
106 let doc = cx.doc();
93− let selection = doc
107+ let text = doc.text().slice(..);
94− .state
108+ let selection = doc.selection().transform(|range| {
109+ movement::move_vertically(
95− .move_selection(Direction::Backward, Granularity::Line, count);
112+ Direction::Backward,
96 doc.set_selection(selection);
117 doc.set_selection(selection);
99pub fn move_line_down(cx: &mut Context) {
120pub fn move_line_down(cx: &mut Context) {
100 let count = cx.count;
121 let count = cx.count;
101 let doc = cx.doc();
122 let doc = cx.doc();
102− let selection = doc
123+ let text = doc.text().slice(..);
103− .state
124+ let selection = doc.selection().transform(|range| {
125+ movement::move_vertically(
104− .move_selection(Direction::Forward, Granularity::Line, count);
128+ Direction::Forward,
105 doc.set_selection(selection);
133 doc.set_selection(selection);
@@ -409,36 +437,64 @@ pub fn half_page_down(cx: &mut Context) {
409pub fn extend_char_left(cx: &mut Context) {
437pub fn extend_char_left(cx: &mut Context) {
410 let count = cx.count;
438 let count = cx.count;
411 let doc = cx.doc();
439 let doc = cx.doc();
412− let selection = doc
440+ let text = doc.text().slice(..);
413− .state
441+ let selection = doc.selection().transform(|range| {
442+ movement::move_horizontally(
414− .extend_selection(Direction::Backward, Granularity::Character, count);
445+ Direction::Backward,
415 doc.set_selection(selection);
450 doc.set_selection(selection);
418pub fn extend_char_right(cx: &mut Context) {
453pub fn extend_char_right(cx: &mut Context) {
419 let count = cx.count;
454 let count = cx.count;
420 let doc = cx.doc();
455 let doc = cx.doc();
421− let selection = doc
456+ let text = doc.text().slice(..);
422− .state
457+ let selection = doc.selection().transform(|range| {
458+ movement::move_horizontally(
423− .extend_selection(Direction::Forward, Granularity::Character, count);
461+ Direction::Forward,
424 doc.set_selection(selection);
466 doc.set_selection(selection);
427pub fn extend_line_up(cx: &mut Context) {
469pub fn extend_line_up(cx: &mut Context) {
428 let count = cx.count;
470 let count = cx.count;
429 let doc = cx.doc();
471 let doc = cx.doc();
430− let selection = doc
472+ let text = doc.text().slice(..);
431− .state
473+ let selection = doc.selection().transform(|range| {
474+ movement::move_vertically(
432− .extend_selection(Direction::Backward, Granularity::Line, count);
477+ Direction::Backward,
433 doc.set_selection(selection);
482 doc.set_selection(selection);
436pub fn extend_line_down(cx: &mut Context) {
485pub fn extend_line_down(cx: &mut Context) {
437 let count = cx.count;
486 let count = cx.count;
438 let doc = cx.doc();
487 let doc = cx.doc();
439− let selection = doc
488+ let text = doc.text().slice(..);
440− .state
489+ let selection = doc.selection().transform(|range| {
490+ movement::move_vertically(
441− .extend_selection(Direction::Forward, Granularity::Line, count);
493+ Direction::Forward,
442 doc.set_selection(selection);
498 doc.set_selection(selection);