@@ -28,16 +28,21 @@ endfunction
28
28
" apply
29
29
"
30
30
function ! s: apply (path , text_edits) abort
31
- let l: current_bufname = bufname (' %' )
32
- let l: current_position = s: Position .cursor ()
31
+ let l: current_bufnr = bufnr (' %' )
32
+ for l: bufnr in range (1 , bufnr (' $' ))
33
+ if index ([fnamemodify (a: path , ' :p' ),fnameescape (fnamemodify (a: path , ' :p' ))], bufname (l: bufnr )) != -1
34
+ let l: target_bufnr = l: bufnr
35
+ break
36
+ endif
37
+ endfor
38
+ if ! exists (' l:target_bufnr' )
39
+ let l: target_bufnr = s: Buffer .ensure (a: path )
40
+ endif
33
41
34
- let l: target_bufnr = s: _switch (a: path )
35
- call s: _substitute (l: target_bufnr , a: text_edits , l: current_position )
36
- let l: current_bufnr = s: _switch (l: current_bufname )
42
+ let l: current_position = s: Position .cursor ()
43
+ call s: Buffer .do (l: target_bufnr , { - > s: _substitute (l: target_bufnr , a: text_edits , l: current_position ) })
37
44
38
- if l: current_bufnr == l: target_bufnr
39
- call cursor (s: Position .lsp_to_vim (' %' , l: current_position ))
40
- endif
45
+ call cursor (s: Position .lsp_to_vim (' %' , l: current_position ))
41
46
endfunction
42
47
43
48
"
@@ -167,18 +172,3 @@ function! s:_fix_text_edits(bufnr, text_edits) abort
167
172
return [l: fixeol , l: text_edits ]
168
173
endfunction
169
174
170
- "
171
- " _switch
172
- "
173
- function ! s: _switch (path ) abort
174
- let l: curr = bufnr (' %' )
175
- let l: next = filereadable (a: path ) ? bufnr (fnameescape (a: path )) : bufnr (a: path )
176
- if l: next >= 0
177
- if l: curr != l: next
178
- execute printf (' noautocmd keepalt keepjumps %sbuffer!' , l: next )
179
- endif
180
- else
181
- execute printf (' noautocmd keepalt keepjumps edit! %s' , fnameescape (a: path ))
182
- endif
183
- return bufnr (' %' )
184
- endfunction
0 commit comments