@@ -15,7 +15,7 @@ function! fern#internal#drawer#hover_popup#init() abort
1515
1616 augroup fern_internal_drawer_hover_popup_init
1717 autocmd ! * <buffer>
18- autocmd CursorMoved <buffer> call s: debounced_show ()
18+ autocmd CursorMoved <buffer> call s: delayed_show ()
1919 autocmd BufLeave <buffer> call s: hide ()
2020 augroup END
2121endfunction
@@ -25,9 +25,9 @@ function! s:available() abort
2525 return has_win && exists (' *win_execute' )
2626endfunction
2727
28- function ! s: debounced_show () abort
28+ function ! s: delayed_show () abort
2929 call s: hide ()
30- let s: show_timer = timer_start (g: fern #drawer_hover_popup_delay, { - > s: show () })
30+ let s: show_timer = timer_start (g: fern #drawer_hover_popup_delay, { - > s: show () })
3131endfunction
3232
3333function ! s: show () abort
@@ -36,7 +36,12 @@ function! s:show() abort
3636 endif
3737 call s: hide ()
3838
39- if strdisplaywidth (getline (' .' )) <= winwidth (0 )
39+ " remove trailing unprintable characters
40+ let line = substitute (getline (' .' ), ' [^[:print:]]*$' , ' ' , ' g' )
41+ let line_width = strdisplaywidth (line )
42+
43+ " don't show a popup if the line fits in the window
44+ if line_width < winwidth (0 )
4045 return
4146 endif
4247
@@ -46,23 +51,25 @@ function! s:show() abort
4651 return
4752 endif
4853
49- let line = getline (' .' )
50- let width = strdisplaywidth (substitute (line , ' [^[:print:]]*$' , ' ' , ' g' ))
5154 if has (' nvim' )
5255 let s: win = nvim_open_win (nvim_create_buf (v: false , v: true ), v: false , {
5356 \ ' relative' : ' win' ,
5457 \ ' bufpos' : [line (' .' ) - 2 , 0 ],
55- \ ' width' : width ,
58+ \ ' width' : line_width ,
5659 \ ' height' : 1 ,
5760 \ ' noautocmd' : v: true ,
5861 \ ' style' : ' minimal' ,
5962 \ })
6063 else
61- let ui_width = screenpos (0 , line (' .' ), 1 ).col - win_screenpos (0 )[1 ]
64+ " calculate position of popup
65+ let drawer_winid = win_getid ()
66+ let pos = getcurpos (drawer_winid)
67+ let curpos = screenpos (drawer_winid, pos[1 ], 1 )
68+
6269 let s: win = popup_create (line , {
6370 \ ' line' : ' cursor' ,
64- \ ' col' : ui_width + 1 ,
65- \ ' maxwidth' : width ,
71+ \ ' col' : curpos[ ' col ' ] ,
72+ \ ' maxwidth' : line_width ,
6673 \ })
6774 endif
6875
0 commit comments