Skip to content

Commit a086fc8

Browse files
committed
Use virtualedit to simplify inserting buffer edits
Previously we used a clumsy hack to handle inserting buffer changes from the server at the end of a line. However there were cases where this still wasn't working correctly. This change temporarily sets virtualedit=all for the buffer, which simplifies the code and removes the hack.
1 parent c526b45 commit a086fc8

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

autoload/OmniSharp/buffer.vim

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ function! OmniSharp#buffer#Update(responseBody) abort
100100
let changes = get(a:responseBody, 'Changes', [])
101101
if type(changes) == type(v:null) | let changes = [] | endif
102102

103-
let virtualedit = &virtualedit ==? 'all'
103+
let virtualedit_bak = &virtualedit
104+
let &l:virtualedit = 'all'
104105
if len(changes)
105106
for change in changes
106107
let text = join(split(change.NewText, '\r\?\n', 1), "\n")
@@ -111,15 +112,6 @@ function! OmniSharp#buffer#Update(responseBody) abort
111112
let start = [change.StartLine, startCol]
112113
let end = [change.EndLine, endCol]
113114
call cursor(start)
114-
if startCol > len(getline('.')) && !virtualedit
115-
" We can't set a mark after the last character of the line, so add an
116-
" extra charaqcter which will be immediately deleted again
117-
noautocmd normal! a<
118-
if start == end
119-
let endCol += 1
120-
let end[0] = endCol
121-
endif
122-
endif
123115
call cursor(change.EndLine, max([1, endCol - 1]))
124116
let lineLen = len(getline('.'))
125117
if change.StartLine < change.EndLine && (endCol == 1 || lineLen == 0)
@@ -156,6 +148,7 @@ function! OmniSharp#buffer#Update(responseBody) abort
156148
let pos[1] = min([pos[1], line('$')])
157149
call setpos('.', pos)
158150
endif
151+
let &l:virtualedit = virtualedit_bak
159152
endfunction
160153

161154
function! OmniSharp#buffer#Valid(...) abort

0 commit comments

Comments
 (0)