Skip to content

Commit

Permalink
Fix cursor pos after text edit (prabirshrestha#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsh7th authored Feb 17, 2020
1 parent 6e78f35 commit 415f6e6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions autoload/lsp/utils/text_edit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function! lsp#utils#text_edit#apply_text_edits(uri, text_edits) abort
endfor
call s:_switch(l:current_bufname)

if l:current_bufname == l:target_bufname
if bufnr(l:current_bufname) == bufnr(l:target_bufname)
let l:length = strlen(getline(l:cursor_pos[0]))
let l:cursor_pos[2] = max([0, l:cursor_pos[1] + l:cursor_pos[2] - l:length])
let l:cursor_pos[1] = min([l:length, l:cursor_pos[1] + l:cursor_pos[2]])
Expand Down Expand Up @@ -58,10 +58,9 @@ function! s:_apply(bufnr, text_edit, cursor_pos) abort
call append(a:text_edit.range.start.line, l:new_lines)

" remove old lines
let l:buffer_length = len(getbufline(a:bufnr, '^', '$'))
execute printf('%s,%sdelete _',
\ l:new_lines_len + a:text_edit.range.start.line + 1,
\ min([l:buffer_length, l:new_lines_len + a:text_edit.range.end.line + 1])
\ min([l:new_lines_len + a:text_edit.range.end.line + 1, line('$')])
\ )

return l:cursor_offset
Expand Down

0 comments on commit 415f6e6

Please sign in to comment.