Skip to content

Commit

Permalink
fmt: fix preventing other windows to be changed, closes #432
Browse files Browse the repository at this point in the history
Thanks to @mhinz

Deleting all lines (%delete) from the buffer would Vim cause to change
the same buffer in other views to be changed as well, which would cause
to change the view and cursor position.

Instead we directly replace the content now, instead of deleting and
appending. This doesn't cause the other view to be changed at all,
because we don't delete all files anymore.
  • Loading branch information
fatih committed May 20, 2015
1 parent d8e83fa commit 99a1732
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions autoload/go/fmt.vim
Expand Up @@ -110,14 +110,16 @@ function! go#fmt#Format(withGoimport)
let default_srr = &srr
set srr=>%s

"delete everything first from the buffer
%delete _

" replace with gofmted content
call append(0, splitted)
" delete any leftover before we replace the whole file. Suppose the
" file had 20 lines, but new output has 10 lines, only 1-10 are
" replaced with setline, remaining lines 11-20 won't get touched. So
" remove them.
if line('$') > len(splitted)
execute len(splitted) .',$delete'
endif

" delete last line that comes from the append call
$delete _
" setline iterates over the list and replaces each line
call setline(1, splitted)

" only clear quickfix if it was previously set, this prevents closing
" other quickfixes
Expand Down

0 comments on commit 99a1732

Please sign in to comment.