@@ -588,7 +588,7 @@ function! s:generate_sub_cmd_insert(text_edit) abort
588
588
let l: new_text = s: parse (a: text_edit [' newText' ])
589
589
590
590
let l: sub_cmd = s: preprocess_cmd (a: text_edit [' range' ])
591
- let l: sub_cmd .= s: generate_move_cmd (l: start_line , l: start_character )
591
+ let l: sub_cmd .= s: generate_move_start_cmd (l: start_line , l: start_character )
592
592
593
593
if len (l: new_text ) == 0
594
594
let l: sub_cmd .= ' x'
@@ -613,9 +613,9 @@ function! s:generate_sub_cmd_replace(text_edit) abort
613
613
let l: new_text = substitute (a: text_edit [' newText' ], ' \n$' , ' ' , ' ' )
614
614
615
615
let l: sub_cmd = s: preprocess_cmd (a: text_edit [' range' ])
616
- let l: sub_cmd .= s: generate_move_cmd (l: start_line , l: start_character ) " move to the first position
616
+ let l: sub_cmd .= s: generate_move_start_cmd (l: start_line , l: start_character ) " move to the first position
617
617
let l: sub_cmd .= ' v'
618
- let l: sub_cmd .= s: generate_move_cmd (l: end_line , l: end_character ) " move to the last position
618
+ let l: sub_cmd .= s: generate_move_end_cmd (l: end_line , l: end_character ) " move to the last position
619
619
620
620
if len (l: new_text ) == 0
621
621
let l: sub_cmd .= ' x'
@@ -627,14 +627,24 @@ function! s:generate_sub_cmd_replace(text_edit) abort
627
627
return l: sub_cmd
628
628
endfunction
629
629
630
- function ! s: generate_move_cmd (line_pos, character_pos) abort
630
+ function ! s: generate_move_start_cmd (line_pos, character_pos) abort
631
631
let l: result = printf (' %dG0' , a: line_pos ) " move the line and set to the cursor at the beginning
632
632
if a: character_pos > 0
633
633
let l: result .= printf (' %dl' , a: character_pos ) " move right until the character
634
634
endif
635
635
return l: result
636
636
endfunction
637
637
638
+ function ! s: generate_move_end_cmd (line_pos, character_pos) abort
639
+ let l: result = printf (' %dG0' , a: line_pos ) " move the line and set to the cursor at the beginning
640
+ if a: character_pos > 0
641
+ let l: result .= printf (' %dl' , a: character_pos ) " move right until the character
642
+ else
643
+ let l: result .= ' $' " move most right
644
+ endif
645
+ return l: result
646
+ endfunction
647
+
638
648
function ! s: parse (text) abort
639
649
" https://stackoverflow.com/questions/71417/why-is-r-a-newline-for-vim
640
650
return substitute (a: text , ' \(^\n|\n$\|\r\n\)' , ' \r' , ' g' )
0 commit comments