mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 09:30:04 +08:00
Add highlight option (#3619)
This commit is contained in:
parent
ae8b0a2428
commit
8331c0a6a1
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
let s:self = {}
|
let s:self = {}
|
||||||
|
let s:self.__dict = SpaceVim#api#import('data#dict')
|
||||||
|
|
||||||
function! s:self.exists() abort
|
function! s:self.exists() abort
|
||||||
return exists('*nvim_open_win')
|
return exists('*nvim_open_win')
|
||||||
@ -29,16 +30,26 @@ endfunction
|
|||||||
" \ 'col' : 0
|
" \ 'col' : 0
|
||||||
" \ })
|
" \ })
|
||||||
function! s:self.open_win(buf, focuce, opt) abort
|
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
|
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/
|
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'),
|
\ 'relative' : get(a:opt, 'relative', 'editor'),
|
||||||
\ 'row' : get(a:opt, 'row', 5),
|
\ 'row' : get(a:opt, 'row', 5),
|
||||||
\ 'col' : get(a:opt, 'col', 5),
|
\ 'col' : get(a:opt, 'col', 5),
|
||||||
\ })
|
\ })
|
||||||
endtry
|
endtry
|
||||||
|
if exists('&winhighlight') && id !=# 0 && has_key(a:opt, 'highlight')
|
||||||
|
call setwinvar(id, '&winhighlight', 'Normal:' . a:opt.highlight)
|
||||||
|
endif
|
||||||
|
return id
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:self.win_config(winid, opt) abort
|
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,并且任然接受四个参数
|
" 2:名称被重命名为 nvim_win_set_config,并且任然接受四个参数
|
||||||
" 3:最新版本名称为 nvim_win_set_config,只接受 2 个参数
|
" 3:最新版本名称为 nvim_win_set_config,只接受 2 个参数
|
||||||
" 这里实现的逻辑就是优先使用最新的api调用方式,当报错时顺历史变更顺序去尝试。
|
" 这里实现的逻辑就是优先使用最新的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
|
try
|
||||||
return nvim_win_set_config(a:winid, a:opt)
|
let id = nvim_win_set_config(a:winid, opt)
|
||||||
catch /^Vim\%((\a\+)\)\=:E119/
|
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'),
|
\ 'relative' : get(a:opt, 'relative', 'editor'),
|
||||||
\ 'row' : get(a:opt, 'row', 5),
|
\ 'row' : get(a:opt, 'row', 5),
|
||||||
\ 'col' : get(a:opt, 'col', 5),
|
\ 'col' : get(a:opt, 'col', 5),
|
||||||
\ })
|
\ })
|
||||||
catch /^Vim\%((\a\+)\)\=:E117/
|
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'),
|
\ 'relative' : get(a:opt, 'relative', 'editor'),
|
||||||
\ 'row' : get(a:opt, 'row', 5),
|
\ 'row' : get(a:opt, 'row', 5),
|
||||||
@ -65,6 +82,10 @@ function! s:self.win_config(winid, opt) abort
|
|||||||
\ })
|
\ })
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
|
if exists('&winhighlight') && id !=# 0 && has_key(a:opt, 'highlight')
|
||||||
|
call setwinvar(id, '&winhighlight', 'Normal:' . a:opt.highlight)
|
||||||
|
endif
|
||||||
|
return id
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ function! s:self.open_win(buffer, focuce, options) abort
|
|||||||
let row = get(a:options, 'row', 1)
|
let row = get(a:options, 'row', 1)
|
||||||
let width = get(a:options, 'width', 1)
|
let width = get(a:options, 'width', 1)
|
||||||
let height = get(a:options, 'height', 1)
|
let height = get(a:options, 'height', 1)
|
||||||
|
let highlight = get(a:options, 'highlight', 'Normal')
|
||||||
let relative = get(a:options, 'relative', 'editor')
|
let relative = get(a:options, 'relative', 'editor')
|
||||||
if relative ==# 'win'
|
if relative ==# 'win'
|
||||||
elseif relative ==# 'cursor'
|
elseif relative ==# 'cursor'
|
||||||
@ -88,6 +89,7 @@ function! s:self.open_win(buffer, focuce, options) abort
|
|||||||
\ 'minheight' : height,
|
\ 'minheight' : height,
|
||||||
\ 'maxwidth' : width,
|
\ 'maxwidth' : width,
|
||||||
\ 'minwidth' : width,
|
\ 'minwidth' : width,
|
||||||
|
\ 'highlight' : highlight,
|
||||||
\ }
|
\ }
|
||||||
endif
|
endif
|
||||||
return popup_create(a:buffer, opt)
|
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 row = get(a:options, 'row', 1)
|
||||||
let width = get(a:options, 'width', 1)
|
let width = get(a:options, 'width', 1)
|
||||||
let height = get(a:options, 'height', 1)
|
let height = get(a:options, 'height', 1)
|
||||||
|
let highlight = get(a:options, 'highlight', 'Normal')
|
||||||
let relative = get(a:options, 'relative', 'editor')
|
let relative = get(a:options, 'relative', 'editor')
|
||||||
if relative ==# 'win'
|
if relative ==# 'win'
|
||||||
elseif relative ==# 'cursor'
|
elseif relative ==# 'cursor'
|
||||||
@ -109,6 +112,7 @@ function! s:self.win_config(winid, options) abort
|
|||||||
\ 'minheight' : height,
|
\ 'minheight' : height,
|
||||||
\ 'maxwidth' : width,
|
\ 'maxwidth' : width,
|
||||||
\ 'minwidth' : width,
|
\ 'minwidth' : width,
|
||||||
|
\ 'highlight' : highlight,
|
||||||
\ }
|
\ }
|
||||||
endif
|
endif
|
||||||
return popup_setoptions(a:winid, opt)
|
return popup_setoptions(a:winid, opt)
|
||||||
|
@ -107,11 +107,12 @@ function! s:self.open_float(st) abort
|
|||||||
let self.__winid = self.__floating.open_win(self.__bufnr,
|
let self.__winid = self.__floating.open_win(self.__bufnr,
|
||||||
\ v:false,
|
\ v:false,
|
||||||
\ {
|
\ {
|
||||||
\ 'relative': 'editor',
|
\ 'relative': 'editor',
|
||||||
\ 'width' : &columns,
|
\ 'width' : &columns,
|
||||||
\ 'height' : 1,
|
\ 'height' : 1,
|
||||||
\ 'row': &lines - 2 ,
|
\ 'highlight' : 'SpaceVim_statusline_a_bold',
|
||||||
\ 'col': 0
|
\ 'row': &lines - 2 ,
|
||||||
|
\ 'col': 0
|
||||||
\ })
|
\ })
|
||||||
endif
|
endif
|
||||||
call setbufvar(self.__bufnr, '&relativenumber', 0)
|
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, '&cursorline', 0)
|
||||||
call setbufvar(self.__bufnr, '&modifiable', 1)
|
call setbufvar(self.__bufnr, '&modifiable', 1)
|
||||||
if exists('*nvim_buf_set_virtual_text')
|
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 setwinvar(win_id2win(self.__winid), '&cursorline', 0)
|
||||||
call nvim_buf_set_virtual_text(
|
call nvim_buf_set_virtual_text(
|
||||||
\ self.__bufnr,
|
\ self.__bufnr,
|
||||||
|
Loading…
Reference in New Issue
Block a user