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 96cbf0c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
9 changes: 6 additions & 3 deletions autoload/youcompleteme.vim
Original file line number Diff line number Diff line change
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
27 changes: 27 additions & 0 deletions test/hover.test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,30 @@ function! Test_Long_Wrapped()

call popup_clear()
endfunction

function! Test_Long_Scrolling()
let f = tempname() . '.cc'
execut 'edit' f
let current_win_id = bufwinid( '%' )
let lines = repeat( [ ' * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ], 50 )
call insert( lines, '/**', 0 )
call extend( lines, [ ' */', 'void f();' ] )
call setline( 1, lines )
call cursor( [ 53, 6 ] )
doautocmd CursorHold
call WaitForAssert( { -> assert_equal( 1, len( popup_list() ) ) }, 10000 )
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' ] )
let new_mouse_line = getwininfo( current_win_id )[ 0 ][ 'height' ]
call test_setmouse( new_mouse_line, 15 )
call feedkeys( "\<ScrollWheelDown>", "xt" )
doautocmd WinScrolled
call assert_equal( 0, len( popup_list() ) )
endfunction

0 comments on commit 96cbf0c

Please sign in to comment.