Allow configuration of floating window appearance

Closes #807.
This commit is contained in:
Andy Stewart
2022-02-02 09:23:45 +00:00
parent e9871cf952
commit 384bf003f6
4 changed files with 47 additions and 16 deletions

View File

@@ -299,6 +299,7 @@ You can customise:
* Whether to clobber or preserve non-gitgutter signs * Whether to clobber or preserve non-gitgutter signs
* The priority of gitgutter's signs. * The priority of gitgutter's signs.
* Whether to use a floating/popup window for hunk previews * 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 * 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. 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. 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 #### 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`. Add `let g:gitgutter_use_location_list = 1` to your `~/.vimrc`.

View File

@@ -431,14 +431,7 @@ function! s:open_hunk_preview_window()
let buf = nvim_create_buf(v:false, v:false) let buf = nvim_create_buf(v:false, v:false)
" Set default width and height for now. " Set default width and height for now.
let s:winid = nvim_open_win(buf, v:false, { let s:winid = nvim_open_win(buf, v:false, g:gitgutter_floating_window_options)
\ 'relative': 'cursor',
\ 'row': 1,
\ 'col': 0,
\ 'width': 42,
\ 'height': &previewheight,
\ 'style': 'minimal'
\ })
call nvim_buf_set_option(buf, 'filetype', 'diff') call nvim_buf_set_option(buf, 'filetype', 'diff')
call nvim_buf_set_option(buf, 'buftype', 'acwrite') call nvim_buf_set_option(buf, 'buftype', 'acwrite')
call nvim_buf_set_option(buf, 'bufhidden', 'delete') call nvim_buf_set_option(buf, 'bufhidden', 'delete')
@@ -461,16 +454,11 @@ function! s:open_hunk_preview_window()
endif endif
if exists('*popup_create') if exists('*popup_create')
let opts = {
\ 'line': 'cursor+1',
\ 'col': 'cursor',
\ 'moved': 'any',
\ }
if g:gitgutter_close_preview_on_escape 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 endif
let s:winid = popup_create('', opts) let s:winid = popup_create('', g:gitgutter_floating_window_options)
call setbufvar(winbufnr(s:winid), '&filetype', 'diff') 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 g:gitgutter_preview_win_floating
if exists('*nvim_open_win') 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. " 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)

View File

@@ -348,6 +348,7 @@ Hunk jumping:~
Hunk previews:~ Hunk previews:~
|g:gitgutter_preview_win_floating| |g:gitgutter_preview_win_floating|
|g:gitgutter_floating_window_options|
|g:gitgutter_close_preview_on_escape| |g:gitgutter_close_preview_on_escape|
Terminal:~ 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 popup windows on Vim you will not be able to stage partial hunks via the
preview window. 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* *g:gitgutter_close_preview_on_escape*
Default: 0 Default: 0

View File

@@ -24,9 +24,22 @@ endfunction
let g:gitgutter_preview_win_location = get(g:, 'gitgutter_preview_win_location', 'bo') let g:gitgutter_preview_win_location = get(g:, 'gitgutter_preview_win_location', 'bo')
if exists('*nvim_open_win') if exists('*nvim_open_win')
let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', 1) 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 else
let default = exists('&previewpopup') ? !empty(&previewpopup) : 0 let default = exists('&previewpopup') ? !empty(&previewpopup) : 0
let g:gitgutter_preview_win_floating = get(g:, 'gitgutter_preview_win_floating', default) 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 endif
let g:gitgutter_enabled = get(g:, 'gitgutter_enabled', 1) let g:gitgutter_enabled = get(g:, 'gitgutter_enabled', 1)
if exists('*sign_unplace') if exists('*sign_unplace')