Prevent undo-hunk scrolling window.

The previous implementation assumed that CTRL-Y and CTRL-E could scroll
by negative counts, i.e. in the opposite direction.  It turns out they
cannot: they treat negative counts as positive ones and always scroll in
the same direction.

This meant that undoing a hunk in the top half of the screen caused the
screen to scroll.

Closes #394.
This commit is contained in:
Andy Stewart
2016-12-16 10:36:30 +00:00
parent e231bbc24a
commit 9639f28037

View File

@@ -209,10 +209,16 @@ function! gitgutter#undo_hunk() abort
call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file(g:gitgutter_git_executable.' apply --reverse --unidiff-zero - '), diff_for_hunk)
" reload file preserving screen line position
let wl = winline()
" CTRL-Y and CTRL-E treat negative counts as positive counts.
let x = line('w0')
silent edit
let offset = wl - winline()
execute "normal! ".offset."\<C-Y>"
let y = line('w0')
let z = x - y
if z > 0
execute "normal! ".z."\<C-E>"
else
execute "normal! ".z."\<C-Y>"
endif
endif
silent! call repeat#set("\<Plug>GitGutterUndoHunk", -1)<CR>