From 8b0e1f941a419258b0877d9a5f71373d76472043 Mon Sep 17 00:00:00 2001 From: Tom Picton Date: Sat, 17 Apr 2021 04:48:10 -0700 Subject: [vim] Support relative-to-window positioning of popup (#2443) Co-authored-by: Junegunn Choi --- plugin/fzf.vim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'plugin/fzf.vim') 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]) -- cgit v1.2.3