diff --git a/autoload/SpaceVim/api/neovim/floating.vim b/autoload/SpaceVim/api/neovim/floating.vim index cfe6b9cbe..83808b081 100644 --- a/autoload/SpaceVim/api/neovim/floating.vim +++ b/autoload/SpaceVim/api/neovim/floating.vim @@ -8,6 +8,7 @@ let s:self = {} +let s:self.__dict = SpaceVim#api#import('data#dict') function! s:self.exists() abort return exists('*nvim_open_win') @@ -29,16 +30,26 @@ endfunction " \ 'col' : 0 " \ }) function! s:self.open_win(buf, focuce, opt) abort + if has_key(a:opt, 'highlight') + let hg = a:opt.highlight + let opt = self.__dict.omit(a:opt, ['highlight']) + else + let opt = a:opt + endif try - return nvim_open_win(a:buf, a:focuce, a:opt) + let id = nvim_open_win(a:buf, a:focuce, opt) catch /^Vim\%((\a\+)\)\=:E119/ - return nvim_open_win(a:buf, a:focuce, get(a:opt, 'width', 5), get(a:opt, 'height', 5), + let id = 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 + if exists('&winhighlight') && id !=# 0 && has_key(a:opt, 'highlight') + call setwinvar(id, '&winhighlight', 'Normal:' . a:opt.highlight) + endif + return id endfunction function! s:self.win_config(winid, opt) abort @@ -47,17 +58,23 @@ function! s:self.win_config(winid, opt) abort " 2:名称被重命名为 nvim_win_set_config,并且任然接受四个参数 " 3:最新版本名称为 nvim_win_set_config,只接受 2 个参数 " 这里实现的逻辑就是优先使用最新的api调用方式,当报错时顺历史变更顺序去尝试。 + if has_key(a:opt, 'highlight') + let hg = a:opt.highlight + let opt = self.__dict.omit(a:opt, ['highlight']) + else + let opt = a:opt + endif try - return nvim_win_set_config(a:winid, a:opt) + let id = nvim_win_set_config(a:winid, opt) catch /^Vim\%((\a\+)\)\=:E119/ - return nvim_win_set_config(a:winid, get(a:opt, 'width', 5), get(a:opt, 'height', 5), + let id = nvim_win_set_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), \ }) catch /^Vim\%((\a\+)\)\=:E117/ - return nvim_win_config(a:winid, get(a:opt, 'width', 5), get(a:opt, 'height', 5), + let id = 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), @@ -65,6 +82,10 @@ function! s:self.win_config(winid, opt) abort \ }) endtry + if exists('&winhighlight') && id !=# 0 && has_key(a:opt, 'highlight') + call setwinvar(id, '&winhighlight', 'Normal:' . a:opt.highlight) + endif + return id endfunction diff --git a/autoload/SpaceVim/api/vim/floating.vim b/autoload/SpaceVim/api/vim/floating.vim index 5f3b3222a..2dd64cac0 100644 --- a/autoload/SpaceVim/api/vim/floating.vim +++ b/autoload/SpaceVim/api/vim/floating.vim @@ -77,6 +77,7 @@ function! s:self.open_win(buffer, focuce, options) abort let row = get(a:options, 'row', 1) let width = get(a:options, 'width', 1) let height = get(a:options, 'height', 1) + let highlight = get(a:options, 'highlight', 'Normal') let relative = get(a:options, 'relative', 'editor') if relative ==# 'win' elseif relative ==# 'cursor' @@ -88,6 +89,7 @@ function! s:self.open_win(buffer, focuce, options) abort \ 'minheight' : height, \ 'maxwidth' : width, \ 'minwidth' : width, + \ 'highlight' : highlight, \ } endif return popup_create(a:buffer, opt) @@ -98,6 +100,7 @@ function! s:self.win_config(winid, options) abort let row = get(a:options, 'row', 1) let width = get(a:options, 'width', 1) let height = get(a:options, 'height', 1) + let highlight = get(a:options, 'highlight', 'Normal') let relative = get(a:options, 'relative', 'editor') if relative ==# 'win' elseif relative ==# 'cursor' @@ -109,6 +112,7 @@ function! s:self.win_config(winid, options) abort \ 'minheight' : height, \ 'maxwidth' : width, \ 'minwidth' : width, + \ 'highlight' : highlight, \ } endif return popup_setoptions(a:winid, opt) diff --git a/autoload/SpaceVim/api/vim/statusline.vim b/autoload/SpaceVim/api/vim/statusline.vim index 9579ac205..002a640d0 100644 --- a/autoload/SpaceVim/api/vim/statusline.vim +++ b/autoload/SpaceVim/api/vim/statusline.vim @@ -107,11 +107,12 @@ function! s:self.open_float(st) abort let self.__winid = self.__floating.open_win(self.__bufnr, \ v:false, \ { - \ 'relative': 'editor', - \ 'width' : &columns, - \ 'height' : 1, - \ 'row': &lines - 2 , - \ 'col': 0 + \ 'relative': 'editor', + \ 'width' : &columns, + \ 'height' : 1, + \ 'highlight' : 'SpaceVim_statusline_a_bold', + \ 'row': &lines - 2 , + \ 'col': 0 \ }) endif call setbufvar(self.__bufnr, '&relativenumber', 0) @@ -120,9 +121,6 @@ function! s:self.open_float(st) abort call setbufvar(self.__bufnr, '&cursorline', 0) call setbufvar(self.__bufnr, '&modifiable', 1) if exists('*nvim_buf_set_virtual_text') - if exists('&winhighlight') - call setwinvar(win_id2win(self.__winid), '&winhighlight', 'Normal:SpaceVim_statusline_a_bold') - endif call setwinvar(win_id2win(self.__winid), '&cursorline', 0) call nvim_buf_set_virtual_text( \ self.__bufnr,