Skip to content

Commit 778630e

Browse files
augustomeloprabirshrestha
authored andcommitted
Fix apply text edits (#193)
The correct way to deal with edge cases (column = 0 or column = line length) is to use selection=excluise (does not delete the last character) and virutaledit=onemore (enable select last line character) instead of transforming the text edits
1 parent 8237501 commit 778630e

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

autoload/lsp/ui/vim.vim

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,18 @@ function! s:apply_text_edits(uri, text_edits) abort
484484

485485
try
486486
let l:was_paste = &paste
487+
let l:was_selection = &selection
488+
let l:was_virtualedit = &virtualedit
489+
487490
set paste
491+
set selection=exclusive
492+
set virtualedit=onemore
493+
488494
execute l:cmd
489495
finally
490496
let &paste = l:was_paste
497+
let &selection = l:was_selection
498+
let &virtualedit = l:was_virtualedit
491499
endtry
492500

493501
let l:i = l:merged_text_edit['end_index']
@@ -601,21 +609,6 @@ function! s:generate_sub_cmd_replace(text_edit) abort
601609
let l:end_character = a:text_edit['range']['end']['character']
602610
let l:new_text = a:text_edit['newText']
603611

604-
" This is necessary since you are removing lines, because when in normal
605-
" mode it cannot grab the last character + 1 (\n).
606-
if l:start_character >= len(getline(l:start_line)) && l:end_character == 0
607-
let l:start_line += 1
608-
let l:start_character = 0
609-
610-
endif
611-
612-
" Since the columns in vim is one-based index, this validation is necessary as
613-
" well
614-
if l:end_character == 0
615-
let l:end_line -= 1
616-
let l:end_character = len(getline(l:end_line))
617-
endif
618-
619612
let l:sub_cmd = s:preprocess_cmd(a:text_edit['range'])
620613
let l:sub_cmd .= s:generate_move_cmd(l:start_line, l:start_character) " move to the first position
621614
let l:sub_cmd .= 'v'

0 commit comments

Comments
 (0)