From 9639f2803738914f2bc782cf3c3863938ded3411 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Fri, 16 Dec 2016 10:36:30 +0000 Subject: [PATCH] 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. --- autoload/gitgutter.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index e543159..0a05a6a 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -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."\" + let y = line('w0') + let z = x - y + if z > 0 + execute "normal! ".z."\" + else + execute "normal! ".z."\" + endif endif silent! call repeat#set("\GitGutterUndoHunk", -1)