[vim] Add support for xoffset and yoffset options for popup

Close https://github.com/junegunn/fzf.vim/issues/942
This commit is contained in:
Junegunn Choi
2020-02-06 10:38:37 +09:00
parent 0896036266
commit a859aa72ee
3 changed files with 27 additions and 13 deletions

View File

@@ -843,10 +843,16 @@ endif
function! s:popup(opts) abort
" Size and position
let width = float2nr(&columns * a:opts.width)
let height = float2nr(&lines * a:opts.height)
let row = float2nr((&lines - height) / 2)
let col = float2nr((&columns - width) / 2)
let width = min([max([0, float2nr(&columns * a:opts.width)]), &columns])
let height = min([max([0, float2nr(&lines * a:opts.height)]), &lines - has('nvim')])
let row = float2nr(get(a:opts, 'yoffset', 0.5) * (&lines - height))
let col = float2nr(get(a:opts, 'xoffset', 0.5) * (&columns - width))
" Managing the differences
let row = min([max([0, row]), &lines - has('nvim') - height])
let col = min([max([0, col]), &columns - width])
let row += !has('nvim')
let col += !has('nvim')
" Border
let edges = get(a:opts, 'rounded', 1) ? ['╭', '╮', '╰', '╯'] : ['┌', '┐', '└', '┘']