Skip to content

Commit

Permalink
Handle scrolling when hover popup is open
Browse files Browse the repository at this point in the history
There are two kinds of scrolling that need to be handled:
1. Scrolling the buffer in a window shifts the buffer, but popups stay
   in place. Instead, we close the popup whenever we receive a
   WinScrolled event.
2. Scrolling the popup contents themselves resets the `updatetime` timer
   and can trigger a second CursorHold event, which leads to YCM
   resetting the hover popup. Instead, only re-display the hover popup
   if it is not already visible.
  • Loading branch information
bstaletic committed Feb 4, 2024
1 parent 0497bb0 commit c360f7a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
9 changes: 6 additions & 3 deletions autoload/youcompleteme.vim
Expand Up @@ -717,6 +717,7 @@ function! s:EnableAutoHover()
augroup YcmBufHover
autocmd! * <buffer>
autocmd CursorHold <buffer> call s:Hover()
autocmd WinScrolled <buffer> call popup_close( s:cursorhold_popup )
augroup END
endif
endfunction
Expand Down Expand Up @@ -1621,9 +1622,11 @@ if exists( '*popup_atcursor' )
return
endif

call youcompleteme#GetCommandResponseAsync(
\ function( 's:ShowHoverResult' ),
\ b:ycm_hover.command )
if empty( popup_getpos( s:cursorhold_popup ) )
call youcompleteme#GetCommandResponseAsync(
\ function( 's:ShowHoverResult' ),
\ b:ycm_hover.command )
endif
endfunction


Expand Down
24 changes: 24 additions & 0 deletions test/hover.test.vim
Expand Up @@ -482,3 +482,27 @@ function! Test_Long_Wrapped()

call popup_clear()
endfunction

function! Test_Long_Scrolling()
let f = tempname() . '.cc'
execut 'edit' f
let lines = repeat( [ ' * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ], 50 )
call insert( lines, 0, '/**' )
call extend( lines, [ ' */', 'void f();' ] )
call setline( 1, lines )
call cursor( [ 54, 6 ] )
normal \D
call WaitForAssert( { -> assert_equal( 1, popup_list() ) } )
let popup_id = popup_list()[ 0 ]
call test_setmouse( 15, 15 )
call feedkeys( "\<ScrollWheelDown>", "xt" )
let win_info = getwininfo( popup_id )[ 0 ]
call assert_notequal( 1, win_info[ 'topline' ] )
doautocmd CursorHold
sleep 1
let win_info = getwininfo( popup_id )[ 0 ]
call assert_notequal( 1, win_info[ 'topline' ] )
call test_setmouse( 15 + win_info[ 'height' ], 15 )
call feedkeys( "\<ScrollWheelDown>", "xt" )
call assert_equal( 0, popup_list() )
endfunction

0 comments on commit c360f7a

Please sign in to comment.