Permalink
Browse files

Ensure BufWritePost,FileChangedShellPost always process buffer.

Before this change the TabEnter/BufEnter logic was intertwined with
the logic for BufWritePost,FileChangedShellPost.

Separating the concerns fixes a minor bug where a TabEnter-BufEnter
combination led to the plugin not updating the diff the first time the
buffer was written.
  • Loading branch information...
1 parent fa25cbb commit 297678a08da0c2d1819d6cb98504f8a843395456 @airblade committed Oct 11, 2016
Showing with 18 additions and 1 deletion.
  1. +18 −1 plugin/gitgutter.vim
View
@@ -196,18 +196,35 @@ augroup gitgutter
endif
if g:gitgutter_eager
- autocmd BufEnter,BufWritePost,FileChangedShellPost *
+ autocmd BufWritePost,FileChangedShellPost * call gitgutter#process_buffer(bufnr(''), 0)
+
+ " When you enter a new tab, BufEnter is only fired if the buffer you enter
+ " is not the one you came from.
+ "
+ " For example:
+ "
+ " `:tab split` fires TabEnter but not BufEnter.
+ " `:tab new` fires TabEnter and BufEnter.
+ "
+ " As and when both TabEnter and BufEnter are fired, we do not want to
+ " process the entered buffer twice. We avoid this by setting and clearing
+ " a flag.
+
+ autocmd BufEnter *
\ if gettabvar(tabpagenr(), 'gitgutter_didtabenter') |
\ call settabvar(tabpagenr(), 'gitgutter_didtabenter', 0) |
\ else |
\ call gitgutter#process_buffer(bufnr(''), 0) |
\ endif
+
autocmd TabEnter *
\ call settabvar(tabpagenr(), 'gitgutter_didtabenter', 1) |
\ call gitgutter#all()
+
if !has('gui_win32')
autocmd FocusGained * call gitgutter#all()
endif
+
else
autocmd BufRead,BufWritePost,FileChangedShellPost * call gitgutter#process_buffer(bufnr(''), 0)
endif

0 comments on commit 297678a

Please sign in to comment.