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

Close https://github.com/junegunn/fzf.vim/issues/942
pull/1857/head
Junegunn Choi 4 years ago
parent 0896036266
commit a859aa72ee
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -198,9 +198,11 @@ When `window` entry is a dictionary, fzf will start in a popup window. The
following options are allowed:
- Required:
- `width` [float]
- `height` [float]
- `width` [float range [0 ~ 1]]
- `height` [float range [0 ~ 1]]
- Optional:
- `yoffset` [float default 0.5 range [0 ~ 1]]
- `xoffset` [float default 0.5 range [0 ~ 1]]
- `highlight` [string default `'Comment'`]: Highlight group for border
- `rounded` [boolean default `v:true`]: Use rounded border
@ -291,10 +293,12 @@ The latest versions of Vim and Neovim include builtin terminal emulator
```vim
" Required:
" - width [float]
" - height [float]
" - width [float range [0 ~ 1]]
" - height [float range [0 ~ 1]]
"
" Optional:
" - xoffset [float default 0.0 range [0 ~ 1]]
" - yoffset [float default 0.0 range [0 ~ 1]]
" - highlight [string default 'Comment']: Highlight group for border
" - rounded [boolean default v:true]: Use rounded border
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }

@ -1,4 +1,4 @@
fzf.txt fzf Last change: February 3 2020
fzf.txt fzf Last change: February 6 2020
FZF - TABLE OF CONTENTS *fzf* *fzf-toc*
==============================================================================
@ -217,9 +217,11 @@ When `window` entry is a dictionary, fzf will start in a popup window. The
following options are allowed:
- Required:
- `width` [float]
- `height` [float]
- `width` [float range [0 ~ 1]]
- `height` [float range [0 ~ 1]]
- Optional:
- `xoffset` [float default 0.0 range [0 ~ 1]]
- `yoffset` [float default 0.0 range [0 ~ 1]]
- `highlight` [string default `'Comment'`]: Highlight group for border
- `rounded` [boolean default `v:true`]: Use rounded border
@ -306,10 +308,12 @@ Starting fzf in a popup window~
*fzf-starting-fzf-in-a-popup-window*
>
" Required:
" - width [float]
" - height [float]
" - width [float range [0 ~ 1]]
" - height [float range [0 ~ 1]]
"
" Optional:
" - xoffset [float default 0.5 range [0 ~ 1]]
" - yoffset [float default 0.5 range [0 ~ 1]]
" - highlight [string default 'Comment']: Highlight group for border
" - rounded [boolean default v:true]: Use rounded border
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }

@ -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) ? ['╭', '╮', '╰', '╯'] : ['┌', '┐', '└', '┘']

Loading…
Cancel
Save