From 5f525476f3ade40e60aa295a8a2a01c0935b0d61 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Thu, 17 Aug 2023 14:14:45 +0100 Subject: [PATCH] Fix in nvim floating preview window closes it Previously the mapping was set in the original window not the floating window, so in the floating window did nothing (when it should have closed it) while in the original window closed the floating window (when it should have done nothing). Fixes #868. --- autoload/gitgutter/hunk.vim | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/autoload/gitgutter/hunk.vim b/autoload/gitgutter/hunk.vim index 5993090..45f3ccc 100644 --- a/autoload/gitgutter/hunk.vim +++ b/autoload/gitgutter/hunk.vim @@ -462,18 +462,16 @@ function! s:open_hunk_preview_window() call nvim_buf_set_option(buf, 'swapfile', v:false) call nvim_buf_set_name(buf, 'gitgutter://hunk-preview') + if g:gitgutter_close_preview_on_escape + let winnr = nvim_win_get_number(s:winid) + execute winnr.'wincmd w' + nnoremap :call gitgutter#hunk#close_hunk_preview_window() + wincmd w + endif + " Assumes cursor is in original window. autocmd CursorMoved,TabLeave ++once call gitgutter#hunk#close_hunk_preview_window() - if g:gitgutter_close_preview_on_escape - " Map to close the floating preview. - nnoremap :call gitgutter#hunk#close_hunk_preview_window() - " Ensure that when the preview window is closed, the map is removed. - autocmd User GitGutterPreviewClosed silent! nunmap - autocmd CursorMoved ++once silent! nunmap - execute "autocmd WinClosed doautocmd" s:nomodeline "User GitGutterPreviewClosed" - endif - return endif