on master help sign in
goto line start/end commands extend when in select mode (#739)
commit05c2a72ccb7f79e8e581d2703816c74543d1995c authorKangwook Lee (이강욱) <pbzweihander@gmail.com> dateSat 11 Sep 2021, 18:31 (5 years ago) parent987d8e6
1 file changed+39−12
helix-term/src/commands.rs+39−12
helix-term/src/commands.rs+39−12
@@ -410,8 +410,7 @@ fn extend_line_down(cx: &mut Context) {
410410 move_impl(cx, move_vertically, Direction::Forward, Movement::Extend)
411411}
412412
413−fn goto_line_end_impl(cx: &mut Context, movement: Movement) {
414− let (view, doc) = current!(cx.editor);
413+fn goto_line_end_impl(view: &mut View, doc: &mut Document, movement: Movement) {
415414 let text = doc.text().slice(..);
416415
417416 let selection = doc.selection(view.id).clone().transform(|range| {
@@ -427,15 +426,24 @@ fn goto_line_end_impl(cx: &mut Context, movement: Movement) {
427426}
428427
429428fn goto_line_end(cx: &mut Context) {
430− goto_line_end_impl(cx, Movement::Move)
429+ let (view, doc) = current!(cx.editor);
430+ goto_line_end_impl(
431+ view,
432+ doc,
433+ if doc.mode == Mode::Select {
434+ Movement::Extend
435+ } else {
436+ Movement::Move
437+ },
438+ )
431439}
432440
433441fn extend_to_line_end(cx: &mut Context) {
434− goto_line_end_impl(cx, Movement::Extend)
442+ let (view, doc) = current!(cx.editor);
443+ goto_line_end_impl(view, doc, Movement::Extend)
435444}
436445
437−fn goto_line_end_newline_impl(cx: &mut Context, movement: Movement) {
438− let (view, doc) = current!(cx.editor);
446+fn goto_line_end_newline_impl(view: &mut View, doc: &mut Document, movement: Movement) {
439447 let text = doc.text().slice(..);
440448
441449 let selection = doc.selection(view.id).clone().transform(|range| {
@@ -448,15 +456,24 @@ fn goto_line_end_newline_impl(cx: &mut Context, movement: Movement) {
448456}
449457
450458fn goto_line_end_newline(cx: &mut Context) {
451− goto_line_end_newline_impl(cx, Movement::Move)
459+ let (view, doc) = current!(cx.editor);
460+ goto_line_end_newline_impl(
461+ view,
462+ doc,
463+ if doc.mode == Mode::Select {
464+ Movement::Extend
465+ } else {
466+ Movement::Move
467+ },
468+ )
452469}
453470
454471fn extend_to_line_end_newline(cx: &mut Context) {
455− goto_line_end_newline_impl(cx, Movement::Extend)
472+ let (view, doc) = current!(cx.editor);
473+ goto_line_end_newline_impl(view, doc, Movement::Extend)
456474}
457475
458−fn goto_line_start_impl(cx: &mut Context, movement: Movement) {
459− let (view, doc) = current!(cx.editor);
476+fn goto_line_start_impl(view: &mut View, doc: &mut Document, movement: Movement) {
460477 let text = doc.text().slice(..);
461478
462479 let selection = doc.selection(view.id).clone().transform(|range| {
@@ -470,11 +487,21 @@ fn goto_line_start_impl(cx: &mut Context, movement: Movement) {
470487}
471488
472489fn goto_line_start(cx: &mut Context) {
473− goto_line_start_impl(cx, Movement::Move)
490+ let (view, doc) = current!(cx.editor);
491+ goto_line_start_impl(
492+ view,
493+ doc,
494+ if doc.mode == Mode::Select {
495+ Movement::Extend
496+ } else {
497+ Movement::Move
498+ },
499+ )
474500}
475501
476502fn extend_to_line_start(cx: &mut Context) {
477− goto_line_start_impl(cx, Movement::Extend)
503+ let (view, doc) = current!(cx.editor);
504+ goto_line_start_impl(view, doc, Movement::Extend)
478505}
479506
480507fn goto_first_nonwhitespace(cx: &mut Context) {