diff --git a/README.mkd b/README.mkd index 9f93c5b..07f9555 100644 --- a/README.mkd +++ b/README.mkd @@ -299,6 +299,7 @@ You can customise: * Whether to clobber or preserve non-gitgutter signs * The priority of gitgutter's signs. * Whether to use a floating/popup window for hunk previews +* The appearance of a floating/popup window for hunk previews * Whether to populate the quickfix list or a location list with all hunks Please note that vim-gitgutter won't override any colours or highlights you've set in your colorscheme. @@ -519,6 +520,11 @@ let g:gitgutter_async = 0 Add `let g:gitgutter_preview_win_floating = 1` to your `~/.vimrc`. Note that on Vim this prevents you staging (partial) hunks via the preview window. +#### The appearance of a floating/popup window for hunk previews + +Set `g:gitgutter_floating_window_options` to a dictionary of the options you want. This dictionary is passed directly to `popup_create()` (Vim) / `nvim_open_win()` (Neovim). + + #### To load all hunks into the current window's location list instead of the quickfix list Add `let g:gitgutter_use_location_list = 1` to your `~/.vimrc`. diff --git a/autoload/gitgutter/hunk.vim b/autoload/gitgutter/hunk.vim index 28059c0..cdf689a 100644 --- a/autoload/gitgutter/hunk.vim +++ b/autoload/gitgutter/hunk.vim @@ -431,14 +431,7 @@ function! s:open_hunk_preview_window() let buf = nvim_create_buf(v:false, v:false) " Set default width and height for now. - let s:winid = nvim_open_win(buf, v:false, { - \ 'relative': 'cursor', - \ 'row': 1, - \ 'col': 0, - \ 'width': 42, - \ 'height': &previewheight, - \ 'style': 'minimal' - \ }) + let s:winid = nvim_open_win(buf, v:false, g:gitgutter_floating_window_options) call nvim_buf_set_option(buf, 'filetype', 'diff') call nvim_buf_set_option(buf, 'buftype', 'acwrite') call nvim_buf_set_option(buf, 'bufhidden', 'delete') @@ -461,16 +454,11 @@ function! s:open_hunk_preview_window() endif if exists('*popup_create') - let opts = { - \ 'line': 'cursor+1', - \ 'col': 'cursor', - \ 'moved': 'any', - \ } if g:gitgutter_close_preview_on_escape - let opts.filter = function('s:close_popup_on_escape') + let g:gitgutter_floating_window_options.filter = function('s:close_popup_on_escape') endif - let s:winid = popup_create('', opts) + let s:winid = popup_create('', g:gitgutter_floating_window_options) call setbufvar(winbufnr(s:winid), '&filetype', 'diff') @@ -515,7 +503,7 @@ function! s:populate_hunk_preview_window(header, body) if g:gitgutter_preview_win_floating if exists('*nvim_open_win') - let height = min([body_length, &previewheight]) + let height = min([body_length, g:gitgutter_floating_window_options.height]) " Assumes cursor is not in previewing window. call nvim_buf_set_var(winbufnr(s:winid), 'hunk_header', a:header) diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index c8d0daa..363803d 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -348,6 +348,7 @@ Hunk jumping:~ Hunk previews:~ |g:gitgutter_preview_win_floating| + |g:gitgutter_floating_window_options| |g:gitgutter_close_preview_on_escape| Terminal:~ @@ -508,6 +509,29 @@ Whether to use floating/popup windows for hunk previews. Note that if you use popup windows on Vim you will not be able to stage partial hunks via the preview window. + *g:gitgutter_floating_window_options* +Default: +> + " Vim + { + \ 'line': 'cursor+1', + \ 'col': 'cursor', + \ 'moved': 'any' + } + + " Neovim + { + \ 'relative': 'cursor', + \ 'row': 1, + \ 'col': 0, + \ 'width': 42, + \ 'height': &previewheight, + \ 'style': 'minimal' + } +< +This dictionary is passed directly to |popup_create()| (Vim) or +|nvim_open_win()| (Neovim). + *g:gitgutter_close_preview_on_escape* Default: 0 diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index eb16e66..ef0bb99 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -24,9 +24,22 @@ endfunction let g:gitgutter_preview_win_location = get(g:, 'gitgutter_preview_win_location', 'bo') if exists('*nvim_open_win') let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', 1) + let g:gitgutter_floating_window_options = get(g:, 'gitgutter_floating_window_options', { + \ 'relative': 'cursor', + \ 'row': 1, + \ 'col': 0, + \ 'width': 42, + \ 'height': &previewheight, + \ 'style': 'minimal' + \ }) else let default = exists('&previewpopup') ? !empty(&previewpopup) : 0 let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', default) + let g:gitgutter_floating_window_options = get(g:, 'gitgutter_floating_window_options', { + \ 'line': 'cursor+1', + \ 'col': 'cursor', + \ 'moved': 'any' + \ }) endif let g:gitgutter_enabled = get(g:, 'gitgutter_enabled', 1) if exists('*sign_unplace')