Skip to content

Commit a808fc3

Browse files
committed
Fix invalid focus behavior when popup is shown
1 parent a7c7c77 commit a808fc3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

autoload/fern/internal/drawer/auto_restore_focus.vim

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endfunction
1313

1414
function! s:auto_restore_focus_pre() abort
1515
let s:info = {
16-
\ 'nwin': winnr('$'),
16+
\ 'nwin': s:nwin(),
1717
\ 'tabpage': tabpagenr(),
1818
\ 'prev': win_getid(winnr('#')),
1919
\}
@@ -24,12 +24,27 @@ function! s:auto_restore_focus() abort
2424
if s:info is# v:null
2525
return
2626
endif
27-
if s:info.tabpage is# tabpagenr() && s:info.nwin > winnr('$')
27+
if s:info.tabpage is# tabpagenr() && s:info.nwin > s:nwin()
2828
call win_gotoid(s:info.prev)
2929
endif
3030
let s:info = v:null
3131
endfunction
3232

33+
if exists('*nvim_win_get_config')
34+
" NOTE:
35+
" Remove Neovim flating window from the total count
36+
function! s:nwin() abort
37+
return len(filter(
38+
\ range(1, winnr('$')),
39+
\ { _, v -> nvim_win_get_config(win_getid(v)).relative ==# '' },
40+
\))
41+
endfunction
42+
else
43+
function! s:nwin() abort
44+
return winnr('$')
45+
endfunction
46+
endif
47+
3348
augroup fern_internal_drawer_auto_restore_focus
3449
autocmd!
3550
autocmd WinEnter * nested call s:auto_restore_focus()

0 commit comments

Comments
 (0)