@@ -15,7 +15,7 @@ function! fern#internal#drawer#hover_popup#init() abort
15
15
16
16
augroup fern_internal_drawer_hover_popup_init
17
17
autocmd ! * <buffer>
18
- autocmd CursorMoved <buffer> call s: debounced_show ()
18
+ autocmd CursorMoved <buffer> call s: delayed_show ()
19
19
autocmd BufLeave <buffer> call s: hide ()
20
20
augroup END
21
21
endfunction
@@ -25,9 +25,9 @@ function! s:available() abort
25
25
return has_win && exists (' *win_execute' )
26
26
endfunction
27
27
28
- function ! s: debounced_show () abort
28
+ function ! s: delayed_show () abort
29
29
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 () })
31
31
endfunction
32
32
33
33
function ! s: show () abort
@@ -36,7 +36,12 @@ function! s:show() abort
36
36
endif
37
37
call s: hide ()
38
38
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 )
40
45
return
41
46
endif
42
47
@@ -46,23 +51,25 @@ function! s:show() abort
46
51
return
47
52
endif
48
53
49
- let line = getline (' .' )
50
- let width = strdisplaywidth (substitute (line , ' [^[:print:]]*$' , ' ' , ' g' ))
51
54
if has (' nvim' )
52
55
let s: win = nvim_open_win (nvim_create_buf (v: false , v: true ), v: false , {
53
56
\ ' relative' : ' win' ,
54
57
\ ' bufpos' : [line (' .' ) - 2 , 0 ],
55
- \ ' width' : width ,
58
+ \ ' width' : line_width ,
56
59
\ ' height' : 1 ,
57
60
\ ' noautocmd' : v: true ,
58
61
\ ' style' : ' minimal' ,
59
62
\ })
60
63
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
+
62
69
let s: win = popup_create (line , {
63
70
\ ' line' : ' cursor' ,
64
- \ ' col' : ui_width + 1 ,
65
- \ ' maxwidth' : width ,
71
+ \ ' col' : curpos[ ' col ' ] ,
72
+ \ ' maxwidth' : line_width ,
66
73
\ })
67
74
endif
68
75
0 commit comments