check background of groups to determine transition. resolves #599.
This commit is contained in:
parent
727192ad6a
commit
be6e4d6dd6
|
@ -23,36 +23,35 @@ function! s:prototype.build()
|
||||||
let side = 1
|
let side = 1
|
||||||
let prev_group = ''
|
let prev_group = ''
|
||||||
let line = ''
|
let line = ''
|
||||||
|
let i = 0
|
||||||
|
let length = len(self._sections)
|
||||||
|
|
||||||
for section in self._sections
|
while i < length
|
||||||
|
let section = self._sections[i]
|
||||||
let group = section[0]
|
let group = section[0]
|
||||||
let contents = section[1]
|
let contents = section[1]
|
||||||
|
|
||||||
if group == '|'
|
if group == ''
|
||||||
|
let line .= contents
|
||||||
|
elseif group == '|'
|
||||||
let side = 0
|
let side = 0
|
||||||
let line .= contents
|
let line .= contents
|
||||||
continue
|
let prev_group = ''
|
||||||
endif
|
else
|
||||||
|
if i == 0
|
||||||
if prev_group != ''
|
let line .= '%#'.group.'#'
|
||||||
if prev_group == group
|
|
||||||
let line .= side ? self._context.left_alt_sep : self._context.right_alt_sep
|
|
||||||
elseif group != ''
|
|
||||||
call airline#highlighter#add_separator(prev_group, group, side)
|
|
||||||
let line .= '%#'.prev_group.'_to_'.group.'#'
|
|
||||||
let line .= side ? self._context.left_sep : self._context.right_sep
|
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
if group != prev_group
|
if prev_group != '' && group != ''
|
||||||
let line .= '%#'.group.'#'
|
let line .= s:get_seperator(self, prev_group, group, side)
|
||||||
endif
|
endif
|
||||||
let line .= s:get_accented_line(self, group, contents)
|
|
||||||
|
|
||||||
if group != ''
|
let line .= s:get_accented_line(self, group, contents)
|
||||||
let prev_group = group
|
let prev_group = group
|
||||||
endif
|
endif
|
||||||
endfor
|
|
||||||
|
let i = i + 1
|
||||||
|
endwhile
|
||||||
|
|
||||||
if !self._context.active
|
if !self._context.active
|
||||||
let line = substitute(line, '%#.\{-}\ze#', '\0_inactive', 'g')
|
let line = substitute(line, '%#.\{-}\ze#', '\0_inactive', 'g')
|
||||||
|
@ -60,6 +59,19 @@ function! s:prototype.build()
|
||||||
return line
|
return line
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:get_seperator(self, prev_group, group, side)
|
||||||
|
let line = ''
|
||||||
|
if airline#highlighter#is_same_bg(a:prev_group, a:group)
|
||||||
|
let line .= a:side ? a:self._context.left_alt_sep : a:self._context.right_alt_sep
|
||||||
|
else
|
||||||
|
call airline#highlighter#add_separator(a:prev_group, a:group, a:side)
|
||||||
|
let line .= '%#'.a:prev_group.'_to_'.a:group.'#'
|
||||||
|
let line .= a:side ? a:self._context.left_sep : a:self._context.right_sep
|
||||||
|
let line .= '%#'.a:group.'#'
|
||||||
|
endif
|
||||||
|
return line
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:get_accented_line(self, group, contents)
|
function! s:get_accented_line(self, group, contents)
|
||||||
if a:self._context.active
|
if a:self._context.active
|
||||||
let contents = []
|
let contents = []
|
||||||
|
|
|
@ -256,6 +256,7 @@ function! s:get_buffers()
|
||||||
|
|
||||||
call b.add_section('airline_tabfill', '')
|
call b.add_section('airline_tabfill', '')
|
||||||
call b.split()
|
call b.split()
|
||||||
|
call b.add_section('airline_tabfill', '')
|
||||||
call b.add_section('airline_tabtype', ' buffers ')
|
call b.add_section('airline_tabtype', ' buffers ')
|
||||||
|
|
||||||
let s:current_bufnr = cur
|
let s:current_bufnr = cur
|
||||||
|
|
|
@ -39,6 +39,16 @@ function! s:get_array(fg, bg, opts)
|
||||||
\ : [ '', '', fg, bg, join(a:opts, ',') ]
|
\ : [ '', '', fg, bg, join(a:opts, ',') ]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! airline#highlighter#is_same_bg(group1, group2)
|
||||||
|
let color1 = airline#highlighter#get_highlight(a:group1)
|
||||||
|
let color2 = airline#highlighter#get_highlight(a:group2)
|
||||||
|
if has('gui_running')
|
||||||
|
return color1[1] == color2[1]
|
||||||
|
else
|
||||||
|
return color1[3] == color2[3]
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! airline#highlighter#get_highlight(group, ...)
|
function! airline#highlighter#get_highlight(group, ...)
|
||||||
let fg = s:get_syn(a:group, 'fg')
|
let fg = s:get_syn(a:group, 'fg')
|
||||||
let bg = s:get_syn(a:group, 'bg')
|
let bg = s:get_syn(a:group, 'bg')
|
||||||
|
|
|
@ -13,9 +13,18 @@ describe 'active builder'
|
||||||
|
|
||||||
it 'should transition colors from one to the next'
|
it 'should transition colors from one to the next'
|
||||||
call s:builder.add_section('Normal', 'hello')
|
call s:builder.add_section('Normal', 'hello')
|
||||||
call s:builder.add_section('NonText', 'world')
|
call s:builder.add_section('Search', 'world')
|
||||||
let stl = s:builder.build()
|
let stl = s:builder.build()
|
||||||
Expect stl =~ '%#Normal#hello%#Normal_to_NonText#>%#NonText#world'
|
Expect stl =~ '%#Normal#hello%#Normal_to_Search#>%#Search#world'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should reuse highlight group if background colors match'
|
||||||
|
highlight Foo1 ctermfg=1 ctermbg=2
|
||||||
|
highlight Foo2 ctermfg=3 ctermbg=2
|
||||||
|
call s:builder.add_section('Foo1', 'hello')
|
||||||
|
call s:builder.add_section('Foo2', 'world')
|
||||||
|
let stl = s:builder.build()
|
||||||
|
Expect stl =~ '%#Foo1#hello>world'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should split left/right sections'
|
it 'should split left/right sections'
|
||||||
|
@ -27,9 +36,9 @@ describe 'active builder'
|
||||||
it 'after split, sections use the right separator'
|
it 'after split, sections use the right separator'
|
||||||
call s:builder.split()
|
call s:builder.split()
|
||||||
call s:builder.add_section('Normal', 'hello')
|
call s:builder.add_section('Normal', 'hello')
|
||||||
call s:builder.add_section('NonText', 'world')
|
call s:builder.add_section('Search', 'world')
|
||||||
let stl = s:builder.build()
|
let stl = s:builder.build()
|
||||||
Expect stl =~ '%#Normal#hello%#Normal_to_NonText#<%#NonText#world'
|
Expect stl =~ 'hello%#Normal_to_Search#<%#Search#world'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not repeat the same highlight group'
|
it 'should not repeat the same highlight group'
|
||||||
|
@ -66,9 +75,9 @@ describe 'inactive builder'
|
||||||
|
|
||||||
it 'should transition colors from one to the next'
|
it 'should transition colors from one to the next'
|
||||||
call s:builder.add_section('Normal', 'hello')
|
call s:builder.add_section('Normal', 'hello')
|
||||||
call s:builder.add_section('NonText', 'world')
|
call s:builder.add_section('Search', 'world')
|
||||||
let stl = s:builder.build()
|
let stl = s:builder.build()
|
||||||
Expect stl =~ '%#Normal_inactive#hello%#Normal_to_NonText_inactive#>%#NonText_inactive#world'
|
Expect stl =~ '%#Normal_inactive#hello%#Normal_to_Search_inactive#>%#Search_inactive#world'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not render accents'
|
it 'should not render accents'
|
||||||
|
|
|
@ -2,6 +2,7 @@ let g:airline_theme = 'dark'
|
||||||
call airline#init#bootstrap()
|
call airline#init#bootstrap()
|
||||||
call airline#init#sections()
|
call airline#init#sections()
|
||||||
source plugin/airline.vim
|
source plugin/airline.vim
|
||||||
|
call airline#load_theme()
|
||||||
|
|
||||||
describe 'default'
|
describe 'default'
|
||||||
before
|
before
|
||||||
|
|
Loading…
Reference in New Issue