mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Expose is-open and close hunk-preview-window functions
This allows custom maps for closing the hunk preview window. See #784.
This commit is contained in:
@@ -64,7 +64,7 @@ function! gitgutter#hunk#next_hunk(count) abort
|
|||||||
if g:gitgutter_show_msg_on_hunk_jumping
|
if g:gitgutter_show_msg_on_hunk_jumping
|
||||||
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
|
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
|
||||||
endif
|
endif
|
||||||
if s:is_preview_window_open()
|
if gitgutter#hunk#is_preview_window_open()
|
||||||
call gitgutter#hunk#preview()
|
call gitgutter#hunk#preview()
|
||||||
endif
|
endif
|
||||||
return
|
return
|
||||||
@@ -95,7 +95,7 @@ function! gitgutter#hunk#prev_hunk(count) abort
|
|||||||
if g:gitgutter_show_msg_on_hunk_jumping
|
if g:gitgutter_show_msg_on_hunk_jumping
|
||||||
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
|
redraw | echo printf('Hunk %d of %d', index(hunks, hunk) + 1, len(hunks))
|
||||||
endif
|
endif
|
||||||
if s:is_preview_window_open()
|
if gitgutter#hunk#is_preview_window_open()
|
||||||
call gitgutter#hunk#preview()
|
call gitgutter#hunk#preview()
|
||||||
endif
|
endif
|
||||||
return
|
return
|
||||||
@@ -249,7 +249,7 @@ function! s:hunk_op(op, ...)
|
|||||||
let hunk_diff = join(hunk_header + hunk_body, "\n")."\n"
|
let hunk_diff = join(hunk_header + hunk_body, "\n")."\n"
|
||||||
|
|
||||||
call s:goto_original_window()
|
call s:goto_original_window()
|
||||||
call s:close_hunk_preview_window()
|
call gitgutter#hunk#close_hunk_preview_window()
|
||||||
call s:stage(hunk_diff)
|
call s:stage(hunk_diff)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -427,7 +427,7 @@ endfunction
|
|||||||
function! s:open_hunk_preview_window()
|
function! s:open_hunk_preview_window()
|
||||||
if g:gitgutter_preview_win_floating
|
if g:gitgutter_preview_win_floating
|
||||||
if exists('*nvim_open_win')
|
if exists('*nvim_open_win')
|
||||||
call s:close_hunk_preview_window()
|
call gitgutter#hunk#close_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.
|
||||||
@@ -446,9 +446,9 @@ function! s:open_hunk_preview_window()
|
|||||||
call nvim_buf_set_name(buf, 'gitgutter://hunk-preview')
|
call nvim_buf_set_name(buf, 'gitgutter://hunk-preview')
|
||||||
|
|
||||||
" Assumes cursor is in original window.
|
" Assumes cursor is in original window.
|
||||||
autocmd CursorMoved <buffer> ++once call s:close_hunk_preview_window()
|
autocmd CursorMoved <buffer> ++once call gitgutter#hunk#close_hunk_preview_window()
|
||||||
if g:gitgutter_close_preview_on_escape
|
if g:gitgutter_close_preview_on_escape
|
||||||
nnoremap <buffer> <silent> <Esc> :<C-U>call <SID>close_hunk_preview_window()<CR>
|
nnoremap <buffer> <silent> <Esc> :<C-U>call gitgutter#hunk#close_hunk_preview_window()<CR>
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -584,7 +584,7 @@ function! s:goto_original_window()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! s:close_hunk_preview_window()
|
function! gitgutter#hunk#close_hunk_preview_window()
|
||||||
let bufnr = s:winid != 0 ? winbufnr(s:winid) : s:preview_bufnr
|
let bufnr = s:winid != 0 ? winbufnr(s:winid) : s:preview_bufnr
|
||||||
call setbufvar(bufnr, '&modified', 0)
|
call setbufvar(bufnr, '&modified', 0)
|
||||||
|
|
||||||
@@ -602,7 +602,7 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
" Only makes sense for traditional, non-floating preview window.
|
" Only makes sense for traditional, non-floating preview window.
|
||||||
function s:is_preview_window_open()
|
function gitgutter#hunk#is_preview_window_open()
|
||||||
for i in range(1, winnr('$'))
|
for i in range(1, winnr('$'))
|
||||||
if getwinvar(i, '&previewwindow')
|
if getwinvar(i, '&previewwindow')
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -190,6 +190,12 @@ Commands for operating on a hunk:~
|
|||||||
the original window with |CTRL-W_p|. Alternatively set
|
the original window with |CTRL-W_p|. Alternatively set
|
||||||
|g:gitgutter_close_preview_on_escape| and use <Esc>.
|
|g:gitgutter_close_preview_on_escape| and use <Esc>.
|
||||||
|
|
||||||
|
Two functions are available for your own logic:
|
||||||
|
>
|
||||||
|
gitgutter#hunk#is_preview_window_open()
|
||||||
|
gitgutter#hunk#close_hunk_preview_window()
|
||||||
|
<
|
||||||
|
|
||||||
Commands for folds:~
|
Commands for folds:~
|
||||||
|
|
||||||
*gitgutter-:GitGutterFold*
|
*gitgutter-:GitGutterFold*
|
||||||
|
|||||||
Reference in New Issue
Block a user