@@ -262,15 +262,15 @@ function! s:GetVar(...) abort
262262 endif
263263endfunction
264264
265- function ! s: CloseFloatingHoverAfterCursorMove (bufname , opened) abort
265+ function ! s: CloseFloatingHoverAfterCursorMove (win_id , opened) abort
266266 if getpos (' .' ) == a: opened
267267 " Just after opening floating window, CursorMoved event is run.
268268 " To avoid closing floating window immediately, check the cursor
269269 " was really moved
270270 return
271271 endif
272272 autocmd ! plugin - LC- neovim- close - hover
273- let winnr = bufwinnr ( bufnr ( a: bufname ) )
273+ let winnr = win_id2win ( a: win_id )
274274 if winnr == -1
275275 return
276276 endif
@@ -279,7 +279,7 @@ endfunction
279279
280280function ! s: CloseFloatingHoverAfterEnterAnotherWin (win_id) abort
281281 let winnr = win_id2win (a: win_id )
282- if winnr == 0
282+ if winnr == -1
283283 " Float window was already closed
284284 autocmd ! plugin - LC- neovim- close - hover
285285 return
@@ -302,13 +302,6 @@ function! s:OpenHoverPreview(bufname, lines, filetype) abort
302302 if s: FLOAT_WINDOW_AVAILABLE
303303 let pos = getpos (' .' )
304304
305- " Unlike preview window, :pclose does not close window. Instead, close
306- " hover window automatically when cursor is moved.
307- let call_after_move = printf (' <SID>CloseFloatingHoverAfterCursorMove("%s", %s)' , a: bufname , string (pos))
308- augroup plugin - LC- neovim- close - hover
309- execute ' autocmd CursorMoved,CursorMovedI,InsertEnter <buffer> call ' . call_after_move
310- augroup END
311-
312305 " Calculate width and height and give margin to lines
313306 let width = 0
314307 for index in range (len (lines ))
@@ -371,7 +364,13 @@ function! s:OpenHoverPreview(bufname, lines, filetype) abort
371364 wincmd p
372365
373366 if s: FLOAT_WINDOW_AVAILABLE
374- execute ' autocmd WinEnter * call <SID>CloseFloatingHoverAfterEnterAnotherWin(' . float_win_id . ' )'
367+ " Unlike preview window, :pclose does not close window. Instead, close
368+ " hover window automatically when cursor is moved.
369+ let call_after_move = printf (' <SID>CloseFloatingHoverAfterCursorMove(%d, %s)' , float_win_id, string (pos))
370+ augroup plugin - LC- neovim- close - hover
371+ execute ' autocmd CursorMoved,CursorMovedI,InsertEnter <buffer> call ' . call_after_move
372+ execute ' autocmd WinEnter * call <SID>CloseFloatingHoverAfterEnterAnotherWin(' . float_win_id . ' )'
373+ augroup END
375374 endif
376375endfunction
377376
0 commit comments