summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-02-06 10:38:37 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-02-06 10:40:57 +0900
commita859aa72ee0ab6e7ae948752906483e468a501ee (patch)
tree093eaf2b79f26138d31bb968cbe482997609556b
parent0896036266dc951ac03c451f1097171a996eb412 (diff)
downloadfzf-a859aa72ee0ab6e7ae948752906483e468a501ee.tar.gz
[vim] Add support for xoffset and yoffset options for popup
Close https://github.com/junegunn/fzf.vim/issues/942
-rw-r--r--README-VIM.md12
-rw-r--r--doc/fzf.txt14
-rw-r--r--plugin/fzf.vim14
3 files changed, 27 insertions, 13 deletions
diff --git a/README-VIM.md b/README-VIM.md
index 103b8e52..88a9308f 100644
--- a/README-VIM.md
+++ b/README-VIM.md
@@ -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 } }
diff --git a/doc/fzf.txt b/doc/fzf.txt
index 51f0d43f..447a6be8 100644
--- a/doc/fzf.txt
+++ b/doc/fzf.txt
@@ -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 } }
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index e4c6e106..5c93f5aa 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -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) ? ['╭', '╮', '╰', '╯'] : ['┌', '┐', '└', '┘']