Skip to content

Commit d0ada5b

Browse files
authored
Merge pull request #449 from brandon1024/popup-fix
Correct hover popup position on right side drawer
2 parents d134808 + 71345e7 commit d0ada5b

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

autoload/fern/internal/drawer.vim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,9 @@ function! fern#internal#drawer#init() abort
5151
call fern#internal#drawer#auto_winfixwidth#init()
5252
call fern#internal#drawer#auto_restore_focus#init()
5353
call fern#internal#drawer#smart_quit#init()
54+
call fern#internal#drawer#hover_popup#init()
5455
call fern#internal#drawer#resize()
5556

56-
if !fern#internal#drawer#is_right_drawer()
57-
call fern#internal#drawer#hover_popup#init()
58-
endif
59-
6057
setlocal winfixwidth
6158
endfunction
6259

autoload/fern/internal/drawer/hover_popup.vim

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
2121
endfunction
@@ -25,9 +25,9 @@ function! s:available() abort
2525
return has_win && exists('*win_execute')
2626
endfunction
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() })
3131
endfunction
3232

3333
function! 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

doc/fern.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,7 @@ VARIABLE *fern-variable*
424424
the width of the drawer.
425425

426426
Note that this feature is required the |win_execute| and
427-
popup/floatwin features.
428-
429-
Note that this feature is only available on a left-sided drawer.
427+
popup/floatwin features.
430428

431429
Default: 0
432430

@@ -531,7 +529,7 @@ VARIABLE *fern-variable*
531529
Default: "default"
532530

533531
*g:fern#drawer_width*
534-
A |Number| width of drawer in default.
532+
A |Number|, the default width of the drawer window.
535533
Default: 30
536534

537535
*g:fern#drawer_keep*

0 commit comments

Comments
 (0)