1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 22:20:06 +08:00

Add highlight option (#3619)

This commit is contained in:
Wang Shidong 2020-07-10 22:25:01 +08:00 committed by GitHub
parent ae8b0a2428
commit 8331c0a6a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 13 deletions

View File

@ -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

View File

@ -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)

View File

@ -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,