@@ -426,6 +426,8 @@ impl MappableCommand {
426
426
goto_implementation, "Goto implementation" ,
427
427
goto_file_start, "Goto line number <n> else file start" ,
428
428
goto_file_end, "Goto file end" ,
429
+ extend_to_file_start, "Extend to line number<n> else file start" ,
430
+ extend_to_file_end, "Extend to file end" ,
429
431
goto_file, "Goto files/URLs in selections" ,
430
432
goto_file_hsplit, "Goto files in selections (hsplit)" ,
431
433
goto_file_vsplit, "Goto files in selections (vsplit)" ,
@@ -438,6 +440,7 @@ impl MappableCommand {
438
440
goto_last_modification, "Goto last modification" ,
439
441
goto_line, "Goto line" ,
440
442
goto_last_line, "Goto last line" ,
443
+ extend_to_last_line, "Extend to last line" ,
441
444
goto_first_diag, "Goto first diagnostic" ,
442
445
goto_last_diag, "Goto last diagnostic" ,
443
446
goto_next_diag, "Goto next diagnostic" ,
@@ -1253,28 +1256,44 @@ fn goto_next_paragraph(cx: &mut Context) {
1253
1256
}
1254
1257
1255
1258
fn goto_file_start ( cx : & mut Context ) {
1259
+ goto_file_start_impl ( cx, Movement :: Move ) ;
1260
+ }
1261
+
1262
+ fn extend_to_file_start ( cx : & mut Context ) {
1263
+ goto_file_start_impl ( cx, Movement :: Extend ) ;
1264
+ }
1265
+
1266
+ fn goto_file_start_impl ( cx : & mut Context , movement : Movement ) {
1256
1267
if cx. count . is_some ( ) {
1257
- goto_line ( cx) ;
1268
+ goto_line_impl ( cx, movement ) ;
1258
1269
} else {
1259
1270
let ( view, doc) = current ! ( cx. editor) ;
1260
1271
let text = doc. text ( ) . slice ( ..) ;
1261
1272
let selection = doc
1262
1273
. selection ( view. id )
1263
1274
. clone ( )
1264
- . transform ( |range| range. put_cursor ( text, 0 , cx . editor . mode == Mode :: Select ) ) ;
1275
+ . transform ( |range| range. put_cursor ( text, 0 , movement == Movement :: Extend ) ) ;
1265
1276
push_jump ( view, doc) ;
1266
1277
doc. set_selection ( view. id , selection) ;
1267
1278
}
1268
1279
}
1269
1280
1270
1281
fn goto_file_end ( cx : & mut Context ) {
1282
+ goto_file_end_impl ( cx, Movement :: Move ) ;
1283
+ }
1284
+
1285
+ fn extend_to_file_end ( cx : & mut Context ) {
1286
+ goto_file_end_impl ( cx, Movement :: Extend )
1287
+ }
1288
+
1289
+ fn goto_file_end_impl ( cx : & mut Context , movement : Movement ) {
1271
1290
let ( view, doc) = current ! ( cx. editor) ;
1272
1291
let text = doc. text ( ) . slice ( ..) ;
1273
1292
let pos = doc. text ( ) . len_chars ( ) ;
1274
1293
let selection = doc
1275
1294
. selection ( view. id )
1276
1295
. clone ( )
1277
- . transform ( |range| range. put_cursor ( text, pos, cx . editor . mode == Mode :: Select ) ) ;
1296
+ . transform ( |range| range. put_cursor ( text, pos, movement == Movement :: Extend ) ) ;
1278
1297
push_jump ( view, doc) ;
1279
1298
doc. set_selection ( view. id , selection) ;
1280
1299
}
@@ -3746,15 +3765,23 @@ fn push_jump(view: &mut View, doc: &Document) {
3746
3765
}
3747
3766
3748
3767
fn goto_line ( cx : & mut Context ) {
3768
+ goto_line_impl ( cx, Movement :: Move ) ;
3769
+ }
3770
+
3771
+ fn goto_line_impl ( cx : & mut Context , movement : Movement ) {
3749
3772
if cx. count . is_some ( ) {
3750
3773
let ( view, doc) = current ! ( cx. editor) ;
3751
3774
push_jump ( view, doc) ;
3752
3775
3753
- goto_line_without_jumplist ( cx. editor , cx. count ) ;
3776
+ goto_line_without_jumplist ( cx. editor , cx. count , movement ) ;
3754
3777
}
3755
3778
}
3756
3779
3757
- fn goto_line_without_jumplist ( editor : & mut Editor , count : Option < NonZeroUsize > ) {
3780
+ fn goto_line_without_jumplist (
3781
+ editor : & mut Editor ,
3782
+ count : Option < NonZeroUsize > ,
3783
+ movement : Movement ,
3784
+ ) {
3758
3785
if let Some ( count) = count {
3759
3786
let ( view, doc) = current ! ( editor) ;
3760
3787
let text = doc. text ( ) . slice ( ..) ;
@@ -3769,13 +3796,21 @@ fn goto_line_without_jumplist(editor: &mut Editor, count: Option<NonZeroUsize>)
3769
3796
let selection = doc
3770
3797
. selection ( view. id )
3771
3798
. clone ( )
3772
- . transform ( |range| range. put_cursor ( text, pos, editor . mode == Mode :: Select ) ) ;
3799
+ . transform ( |range| range. put_cursor ( text, pos, movement == Movement :: Extend ) ) ;
3773
3800
3774
3801
doc. set_selection ( view. id , selection) ;
3775
3802
}
3776
3803
}
3777
3804
3778
3805
fn goto_last_line ( cx : & mut Context ) {
3806
+ goto_last_line_impl ( cx, Movement :: Move )
3807
+ }
3808
+
3809
+ fn extend_to_last_line ( cx : & mut Context ) {
3810
+ goto_last_line_impl ( cx, Movement :: Extend )
3811
+ }
3812
+
3813
+ fn goto_last_line_impl ( cx : & mut Context , movement : Movement ) {
3779
3814
let ( view, doc) = current ! ( cx. editor) ;
3780
3815
let text = doc. text ( ) . slice ( ..) ;
3781
3816
let line_idx = if text. line ( text. len_lines ( ) - 1 ) . len_chars ( ) == 0 {
@@ -3788,7 +3823,7 @@ fn goto_last_line(cx: &mut Context) {
3788
3823
let selection = doc
3789
3824
. selection ( view. id )
3790
3825
. clone ( )
3791
- . transform ( |range| range. put_cursor ( text, pos, cx . editor . mode == Mode :: Select ) ) ;
3826
+ . transform ( |range| range. put_cursor ( text, pos, movement == Movement :: Extend ) ) ;
3792
3827
3793
3828
push_jump ( view, doc) ;
3794
3829
doc. set_selection ( view. id , selection) ;
0 commit comments