@@ -755,14 +755,36 @@ endfunction
755755
756756function ! coc#float#reposition_cursor_floats (event ) abort
757757 if empty (a: event ) | return | endif
758+ let view_cache = {}
758759 for winid in coc#float#get_float_win_list ()
759760 let source = getwinvar (winid, ' cursor_float_source' , 0 )
760761 if ! source | continue | endif
761762 let evt = get (a: event , string (source ), {})
763+ if empty (evt) | continue | endif
762764 let dy = - get (evt, ' topline' , 0 )
763765 let dx = - get (evt, ' leftcol' , 0 )
764766 if dy == 0 && dx == 0 | continue | endif
767+ if ! has_key (view_cache, source )
768+ let view_cache[source ] = s: get_cursor_float_source_view (source )
769+ endif
770+ let view = view_cache[source ]
771+ if empty (view )
772+ call setwinvar (winid, ' cursor_float_source' , 0 )
773+ call setwinvar (winid, ' cursor_float_source_view' , {})
774+ continue
775+ endif
776+ let previous = {
777+ \ ' topline' : get (view , ' topline' , 0 ) - get (evt, ' topline' , 0 ),
778+ \ ' leftcol' : get (view , ' leftcol' , 0 ) - get (evt, ' leftcol' , 0 )
779+ \ }
780+ let tracked = getwinvar (winid, ' cursor_float_source_view' , previous )
781+ if get (tracked, ' topline' , 0 ) != get (previous , ' topline' , 0 )
782+ \ || get (tracked, ' leftcol' , 0 ) != get (previous , ' leftcol' , 0 )
783+ call setwinvar (winid, ' cursor_float_source_view' , view )
784+ continue
785+ endif
765786 call s: move_cursor_float (winid, dy , dx)
787+ call setwinvar (winid, ' cursor_float_source_view' , view )
766788 endfor
767789endfunction
768790
@@ -1414,7 +1436,25 @@ function! s:win_setview(winid, topline, lnum) abort
14141436endfunction
14151437
14161438function ! s: track_cursor_float (winid, config) abort
1417- call setwinvar (a: winid , ' cursor_float_source' , get (a: config , ' relative' , ' ' ) == # ' cursor' ? win_getid () : 0 )
1439+ if get (a: config , ' relative' , ' ' ) == # ' cursor'
1440+ let source = win_getid ()
1441+ call setwinvar (a: winid , ' cursor_float_source' , source )
1442+ call setwinvar (a: winid , ' cursor_float_source_view' , s: get_cursor_float_source_view (source ))
1443+ else
1444+ call setwinvar (a: winid , ' cursor_float_source' , 0 )
1445+ call setwinvar (a: winid , ' cursor_float_source_view' , {})
1446+ endif
1447+ endfunction
1448+
1449+ function ! s: get_cursor_float_source_view (winid) abort
1450+ let info = get (getwininfo (a: winid ), 0 , {})
1451+ if empty (info)
1452+ return {}
1453+ endif
1454+ return {
1455+ \ ' topline' : get (info, ' topline' , 0 ),
1456+ \ ' leftcol' : get (info, ' leftcol' , 0 )
1457+ \ }
14181458endfunction
14191459
14201460function ! s: set_float_defaults (winid, config) abort
0 commit comments