mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Maintain backward compatibility in hunk preview code
win_getid() was introduced in Vim 7.4.1557. The code uses it to remember the id of the preview window. In newer Vims or Neovim this could be a floating window but pre-7.4.1557 it can only be an ordinary preview window. And in that case we only need the preview window's buffer number. This commit uses the buffer number when win_getid() isn't available. Fixes #683.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
let s:winid = 0
|
||||
let s:preview_bufnr = 0
|
||||
let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ? '<nomodeline>' : ''
|
||||
|
||||
function! gitgutter#hunk#set_hunks(bufnr, hunks) abort
|
||||
@@ -442,7 +443,11 @@ function! s:open_hunk_preview_window()
|
||||
if !&previewwindow
|
||||
noautocmd execute g:gitgutter_preview_win_location &previewheight 'new gitgutter://hunk-preview'
|
||||
doautocmd WinEnter
|
||||
if exists('*win_getid')
|
||||
let s:winid = win_getid()
|
||||
else
|
||||
let s:preview_bufnr = bufnr('')
|
||||
endif
|
||||
set previewwindow
|
||||
setlocal filetype=diff buftype=acwrite bufhidden=delete
|
||||
" Reset some defaults in case someone else has changed them.
|
||||
@@ -511,7 +516,8 @@ endfunction
|
||||
function! s:enable_staging_from_hunk_preview_window()
|
||||
augroup gitgutter_hunk_preview
|
||||
autocmd!
|
||||
execute 'autocmd BufWriteCmd <buffer='.winbufnr(s:winid).'> GitGutterStageHunk'
|
||||
let bufnr = s:winid != 0 ? winbufnr(s:winid) : s:preview_bufnr
|
||||
execute 'autocmd BufWriteCmd <buffer='.bufnr.'> GitGutterStageHunk'
|
||||
augroup END
|
||||
endfunction
|
||||
|
||||
@@ -523,7 +529,8 @@ endfunction
|
||||
|
||||
|
||||
function! s:close_hunk_preview_window()
|
||||
call setbufvar(winbufnr(s:winid), '&modified', 0)
|
||||
let bufnr = s:winid != 0 ? winbufnr(s:winid) : s:preview_bufnr
|
||||
call setbufvar(bufnr, '&modified', 0)
|
||||
|
||||
if g:gitgutter_preview_win_floating
|
||||
if win_id2win(s:winid) > 0
|
||||
@@ -534,4 +541,5 @@ function! s:close_hunk_preview_window()
|
||||
endif
|
||||
|
||||
let s:winid = 0
|
||||
let s:preview_bufnr = 0
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user