Skip to content

Commit

Permalink
Hide floating window when using gf like commands, close #208, also …
Browse files Browse the repository at this point in the history
…close
  • Loading branch information
voldikss committed Dec 17, 2020
1 parent bef7e8d commit 4691f3b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
27 changes: 18 additions & 9 deletions autoload/floaterm/window.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ function! s:format_title(bufnr, text) abort
return title
endfunction

function! s:hide_border(bufnr, ...) abort
let winid = nvim_buf_get_var(a:bufnr, 'floaterm_winid')
let bd_winid = getwinvar(winid, 'floatermborder_winid', -1)
if s:winexists(bd_winid)
call nvim_win_close(bd_winid, v:true)
function! s:hide_border(winid) abort
if s:winexists(a:winid)
let bd_winid = getwinvar(a:winid, 'floatermborder_winid', -1)
if s:winexists(bd_winid)
call nvim_win_close(bd_winid, v:true)
endif
call nvim_win_set_var(a:winid, 'floatermborder_winid', -1)
endif
call nvim_win_set_var(winid, 'floatermborder_winid', -1)
endfunction

function! s:get_floatwin_pos(width, height, pos) abort
Expand Down Expand Up @@ -120,14 +121,22 @@ function! s:winexists(winid) abort
return !empty(getwininfo(a:winid))
endfunction

function s:is_floating(winid) abort
return s:winexists(a:winid) && has_key(nvim_win_get_config(a:winid), 'anchor')
endfunction

function! s:on_floaterm_open(bufnr, winid, opts) abort
call setbufvar(a:bufnr, 'floaterm_winid', a:winid)
call setbufvar(a:bufnr, 'floaterm_opts', a:opts)
call setbufvar(a:bufnr, '&buflisted', 0)
call setbufvar(a:bufnr, '&filetype', 'floaterm')
if has('nvim')
" TODO: need to be reworked
execute printf('autocmd BufHidden <buffer=%s> ++once call s:hide_border(%s)', a:bufnr, a:bufnr)
execute printf(
\ 'autocmd BufHidden <buffer=%s> ++once call floaterm#window#hide(%s)',
\ a:bufnr,
\ a:bufnr
\ )
endif
endfunction

Expand Down Expand Up @@ -270,8 +279,8 @@ function! floaterm#window#hide(bufnr) abort
let winid = getbufvar(a:bufnr, 'floaterm_winid', -1)
if winid == -1 | return | endif
if has('nvim')
if !s:winexists(winid) | return | endif
call nvim_win_close(winid, v:true)
call s:hide_border(winid)
call timer_start(10, { -> s:is_floating(winid) ? nvim_win_close(winid, v:true) : v:null })
else
if exists('*win_gettype')
if win_gettype() == 'popup'
Expand Down
21 changes: 21 additions & 0 deletions test/test_others/test_gf.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
" vim:ft=vim

Execute(Open in normal window when using `gf`):
silent !touch test.txt
FloatermNew
stopinsert
let @" = 'test.txt'
normal! p
normal! $
sleep 100m
normal! gf
AssertEqual 'test.txt', bufname()
sleep 100m
AssertEqual 0, has_key(nvim_win_get_config(win_getid()), 'anchor')
silent !rm test.txt

Execute(Exit):
call feedkeys("\<Esc>")
FloatermKill!
sleep 100m
call feedkeys("\<CR>")

0 comments on commit 4691f3b

Please sign in to comment.