Skip to content

Commit

Permalink
Close preview on escape: only map <Esc> while preview open
Browse files Browse the repository at this point in the history
This only applies to floating preview windows on Neovim.

Handles the following way of closing the floating preview:

- <Esc>
- Moving cursor
- 2<C-W>c (where 2 is the floating window's window number)
- <C-W><C-W> to move into and out of the floating window

Closes airblade#786.
  • Loading branch information
airblade committed Jun 3, 2021
1 parent 2571c8f commit 68a8cb3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions autoload/gitgutter/hunk.vim
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,14 @@ function! s:open_hunk_preview_window()

" Assumes cursor is in original window.
autocmd CursorMoved <buffer> ++once call gitgutter#hunk#close_hunk_preview_window()

if g:gitgutter_close_preview_on_escape
" Map <Esc> to close the floating preview.
nnoremap <buffer> <silent> <Esc> :<C-U>call gitgutter#hunk#close_hunk_preview_window()<CR>
" Ensure that when the preview window is closed, the map is removed.
autocmd User GitGutterPreviewClosed silent! nunmap <buffer> <Esc>
autocmd CursorMoved <buffer> ++once silent! nunmap <buffer> <Esc>
execute "autocmd WinClosed <buffer=".winbufnr(s:winid)."> doautocmd" s:nomodeline "User GitGutterPreviewClosed"
endif

return
Expand Down

0 comments on commit 68a8cb3

Please sign in to comment.