From e6e6b6d76cf8464292bf5a6ea57a26fdaec359ff Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Mon, 6 May 2019 12:50:10 +0800 Subject: [PATCH] Update floating support (#2789) close #2688 --- autoload/SpaceVim/api/neovim/floating.vim | 58 +++++++++++++++++++++++ autoload/SpaceVim/mapping/guide.vim | 5 +- autoload/SpaceVim/plugins/flygrep.vim | 3 +- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 autoload/SpaceVim/api/neovim/floating.vim diff --git a/autoload/SpaceVim/api/neovim/floating.vim b/autoload/SpaceVim/api/neovim/floating.vim new file mode 100644 index 000000000..1f0907654 --- /dev/null +++ b/autoload/SpaceVim/api/neovim/floating.vim @@ -0,0 +1,58 @@ +"============================================================================= +" floating.vim --- neovim#floating api +" Copyright (c) 2016-2017 Wang Shidong & Contributors +" Author: Wang Shidong < wsdjeg at 163.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= + + +let s:self = {} +" in old version nvim_open_win api is: +" call nvim_open_win(s:bufnr, v:true, &columns, 12, +" \ { +" \ 'relative': 'editor', +" \ 'row': &lines - 14, +" \ 'col': 0 +" \ }) +" if exists('*nvim_open_win') +" call nvim_win_set_config(win_getid(s:gwin), +" \ { +" \ 'relative': 'editor', +" \ 'width' : &columns, +" \ 'height' : layout.win_dim + 2, +" \ 'row' : &lines - layout.win_dim - 4, +" \ 'col' : 0 +" \ }) +function! s:self.open_win(buf, focuce, opt) abort + try + call nvim_open_win(a:buf, a:focuce, a:opt) + catch /^Vim\%((\a\+)\)\=:E119/ + call nvim_open_win(a:buf, a:focuce, get(a:opt, 'width', 5), get(a:opt, 'height', 5), + \ { + \ 'relative' : get(a:opt, 'relative', 'editor'), + \ 'row' : get(a:opt, 'row', 5), + \ 'col' : get(a:opt, 'col', 5), + \ }) + endtry +endfunction + +function! s:self.win_config(winid, opt) abort + + try + call nvim_win_config(a:winid, a:opt) + catch /^Vim\%((\a\+)\)\=:E119/ + call nvim_win_config(a:winid, get(a:opt, 'width', 5), get(a:opt, 'height', 5), + \ { + \ 'relative' : get(a:opt, 'relative', 'editor'), + \ 'row' : get(a:opt, 'row', 5), + \ 'col' : get(a:opt, 'col', 5), + \ }) + endtry + +endfunction + + +function! SpaceVim#api#neovim#floating#get() abort + return deepcopy(s:self) +endfunction diff --git a/autoload/SpaceVim/mapping/guide.vim b/autoload/SpaceVim/mapping/guide.vim index 48a70e023..b81ebf2ca 100644 --- a/autoload/SpaceVim/mapping/guide.vim +++ b/autoload/SpaceVim/mapping/guide.vim @@ -15,6 +15,7 @@ scriptencoding utf-8 let s:CMP = SpaceVim#api#import('vim#compatible') let s:STR = SpaceVim#api#import('data#string') let s:KEY = SpaceVim#api#import('vim#key') +let s:FLOATING = SpaceVim#api#import('neovim#floating') function! SpaceVim#mapping#guide#has_configuration() abort "{{{ return exists('s:desc_lookup') @@ -393,7 +394,7 @@ function! s:start_buffer() abort " {{{ setlocal modifiable if exists('*nvim_open_win') - call nvim_win_set_config(win_getid(s:gwin), + call s:FLOATING.win_config(win_getid(s:gwin), \ { \ 'relative': 'editor', \ 'width' : &columns, @@ -509,7 +510,7 @@ function! s:winopen() abort " {{{ if !bufexists(s:bufnr) let s:bufnr = nvim_create_buf(v:false,v:false) endif - call nvim_open_win(s:bufnr, v:true, + call s:FLOATING.open_win(s:bufnr, v:true, \ { \ 'relative': 'editor', \ 'width' : &columns, diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index 46d1c5db7..0196874ac 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -14,6 +14,7 @@ let s:SYS = SpaceVim#api#import('system') let s:BUFFER = SpaceVim#api#import('vim#buffer') let s:LIST = SpaceVim#api#import('data#list') let s:HI = SpaceVim#api#import('vim#highlight') +let s:FLOATING = SpaceVim#api#import('neovim#floating') " }}} let s:grepid = 0 @@ -599,7 +600,7 @@ function! SpaceVim#plugins#flygrep#open(agrv) abort if exists('*nvim_open_win') let s:buffer_id = nvim_create_buf(v:false, v:false) let flygrep_win_height = 16 - let s:flygrep_win_id = nvim_open_win(s:buffer_id, v:true, + let s:flygrep_win_id = s:FLOATING.open_win(s:buffer_id, v:true, \ { \ 'relative': 'editor', \ 'width' : &columns,