summaryrefslogtreecommitdiffstats
path: root/plugin/fzf.vim
diff options
context:
space:
mode:
authorTom Picton <tom@tompicton.com>2021-04-17 04:48:10 -0700
committerGitHub <noreply@github.com>2021-04-17 20:48:10 +0900
commit8b0e1f941a419258b0877d9a5f71373d76472043 (patch)
treea95b57ee3888f119c381b21510f13d25002db165 /plugin/fzf.vim
parentc7c5e7670a9bccf5c7ba2b8dd3fa73135be2b734 (diff)
[vim] Support relative-to-window positioning of popup (#2443)
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
Diffstat (limited to 'plugin/fzf.vim')
-rw-r--r--plugin/fzf.vim16
1 files changed, 12 insertions, 4 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 26dcf974..9cebed48 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -972,11 +972,19 @@ else
endif
function! s:popup(opts) abort
+ let xoffset = get(a:opts, 'xoffset', 0.5)
+ let yoffset = get(a:opts, 'yoffset', 0.5)
+ let relative = get(a:opts, 'relative', 0)
+
+ " Use current window size for positioning relatively positioned popups
+ let columns = relative ? winwidth(0) : &columns
+ let lines = relative ? winheight(0) : &lines
+
" Size and position
- let width = min([max([8, a:opts.width > 1 ? a:opts.width : float2nr(&columns * a:opts.width)]), &columns])
- let height = min([max([4, a:opts.height > 1 ? a:opts.height : 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))
+ let width = min([max([8, a:opts.width > 1 ? a:opts.width : float2nr(columns * a:opts.width)]), columns])
+ let height = min([max([4, a:opts.height > 1 ? a:opts.height : float2nr(lines * a:opts.height)]), lines - has('nvim')])
+ let row = float2nr(yoffset * (lines - height)) + (relative ? win_screenpos(0)[0] : 0)
+ let col = float2nr(xoffset * (columns - width)) + (relative ? win_screenpos(0)[1] : 0)
" Managing the differences
let row = min([max([0, row]), &lines - has('nvim') - height])