Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Close floating window when entering other window on WinEnter
  • Loading branch information
rhysd committed Mar 14, 2019
commit 1a7748f49b3eb3e6d5f25560f80b589f9dd411b9
31 changes: 23 additions & 8 deletions autoload/LanguageClient.vim
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,33 @@ function! s:GetVar(...) abort
endif
endfunction

function! s:CloseFloatingHover(bufname, opened) abort
function! s:CloseFloatingHoverAfterCursorMove(bufname, opened) abort
if getpos('.') == a:opened
" Just after opening floating window, CursorMoved event is run.
" To avoid closing floating window immediately, check the cursor
" was really moved
return
endif
autocmd! plugin-LC-neovim-close-hover
let bufnr = bufnr(a:bufname)
if bufnr == -1
let winnr = bufwinnr(bufnr(a:bufname))
if winnr == -1
return
endif
let winnr = bufwinnr(bufnr)
if winnr == -1
execute winnr . 'wincmd c'
endfunction

function! s:CloseFloatingHoverAfterEnterAnotherWin(win_id) abort
let winnr = win_id2win(a:win_id)
if winnr == 0
" Float window was already closed
autocmd! plugin-LC-neovim-close-hover
return
endif
if winnr == winnr()
" Cursor is moving into floating window. Do not close it
return
endif
autocmd! plugin-LC-neovim-close-hover
execute winnr . 'wincmd c'
endfunction

Expand All @@ -293,9 +304,9 @@ function! s:OpenHoverPreview(bufname, lines, filetype) abort

" Unlike preview window, :pclose does not close window. Instead, close
" hover window automatically when cursor is moved.
let params = printf('"%s", %s', a:bufname, string(pos))
let call_after_move = printf('<SID>CloseFloatingHoverAfterCursorMove("%s", %s)', a:bufname, string(pos))
augroup plugin-LC-neovim-close-hover
execute 'autocmd CursorMoved,CursorMovedI,InsertEnter <buffer> call <SID>CloseFloatingHover(' . params . ')'
execute 'autocmd CursorMoved,CursorMovedI,InsertEnter <buffer> call ' . call_after_move
augroup END

" Calculate width and height and give margin to lines
Expand Down Expand Up @@ -333,7 +344,7 @@ function! s:OpenHoverPreview(bufname, lines, filetype) abort
let col = 1
endif

call nvim_open_win(bufnr('%'), v:true, width, height, {
let float_win_id = nvim_open_win(bufnr('%'), v:true, width, height, {
\ 'relative': 'cursor',
\ 'anchor': vert . hor,
\ 'row': row,
Expand All @@ -358,6 +369,10 @@ function! s:OpenHoverPreview(bufname, lines, filetype) abort
setlocal nomodified nomodifiable

wincmd p

if s:FLOAT_WINDOW_AVAILABLE
execute 'autocmd WinEnter * call <SID>CloseFloatingHoverAfterEnterAnotherWin(' . float_win_id . ')'
endif
endfunction

let s:id = 1
Expand Down