From a859aa72ee0ab6e7ae948752906483e468a501ee Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 6 Feb 2020 10:38:37 +0900 Subject: [PATCH] [vim] Add support for xoffset and yoffset options for popup Close https://github.com/junegunn/fzf.vim/issues/942 --- README-VIM.md | 12 ++++++++---- doc/fzf.txt | 14 +++++++++----- plugin/fzf.vim | 14 ++++++++++---- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/README-VIM.md b/README-VIM.md index 103b8e5..88a9308 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 51f0d43..447a6be 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 e4c6e10..5c93f5a 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) ? ['╭', '╮', '╰', '╯'] : ['┌', '┐', '└', '┘']