Account for wrapping when resizing preview window

Fixes #708.
This commit is contained in:
Andy Stewart
2020-05-29 10:46:42 +01:00
parent b356cc9a7d
commit 9784226ba7

View File

@@ -460,10 +460,11 @@ endfunction
" Preview window: assumes cursor is in preview window. " Preview window: assumes cursor is in preview window.
function! s:populate_hunk_preview_window(header, body) function! s:populate_hunk_preview_window(header, body)
let body_length = len(a:body) let body_length = len(a:body)
let height = min([body_length, &previewheight])
if g:gitgutter_preview_win_floating if g:gitgutter_preview_win_floating
if exists('*nvim_open_win') if exists('*nvim_open_win')
let height = min([body_length, &previewheight])
" Assumes cursor is not in previewing window. " Assumes cursor is not in previewing window.
call nvim_buf_set_var(winbufnr(s:winid), 'hunk_header', a:header) call nvim_buf_set_var(winbufnr(s:winid), 'hunk_header', a:header)
@@ -496,12 +497,16 @@ function! s:populate_hunk_preview_window(header, body)
else else
let b:hunk_header = a:header let b:hunk_header = a:header
execute 'resize' height
%delete _ %delete _
call setline(1, a:body) call setline(1, a:body)
setlocal nomodified setlocal nomodified
normal! G$
let height = min([winline(), &previewheight])
execute 'resize' height
1
call clearmatches() call clearmatches()
for region in gitgutter#diff_highlight#process(a:body) for region in gitgutter#diff_highlight#process(a:body)
let group = region[1] == '+' ? 'GitGutterAddIntraLine' : 'GitGutterDeleteIntraLine' let group = region[1] == '+' ? 'GitGutterAddIntraLine' : 'GitGutterDeleteIntraLine'