[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
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 27 additions and 13 deletions

View File

@ -198,9 +198,11 @@ When `window` entry is a dictionary, fzf will start in a popup window. The
following options are allowed: following options are allowed:
- Required: - Required:
- `width` [float] - `width` [float range [0 ~ 1]]
- `height` [float] - `height` [float range [0 ~ 1]]
- Optional: - 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 - `highlight` [string default `'Comment'`]: Highlight group for border
- `rounded` [boolean default `v:true`]: Use rounded 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 ```vim
" Required: " Required:
" - width [float] " - width [float range [0 ~ 1]]
" - height [float] " - height [float range [0 ~ 1]]
" "
" Optional: " 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 " - highlight [string default 'Comment']: Highlight group for border
" - rounded [boolean default v:true]: Use rounded border " - rounded [boolean default v:true]: Use rounded border
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } } let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }

View File

@ -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* 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: following options are allowed:
- Required: - Required:
- `width` [float] - `width` [float range [0 ~ 1]]
- `height` [float] - `height` [float range [0 ~ 1]]
- Optional: - 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 - `highlight` [string default `'Comment'`]: Highlight group for border
- `rounded` [boolean default `v:true`]: Use rounded 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* *fzf-starting-fzf-in-a-popup-window*
> >
" Required: " Required:
" - width [float] " - width [float range [0 ~ 1]]
" - height [float] " - height [float range [0 ~ 1]]
" "
" Optional: " 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 " - highlight [string default 'Comment']: Highlight group for border
" - rounded [boolean default v:true]: Use rounded border " - rounded [boolean default v:true]: Use rounded border
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } } let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }

View File

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