diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim index b3c317e8..52c3f5ac 100644 --- a/autoload/airline/builder.vim +++ b/autoload/airline/builder.vim @@ -59,15 +59,28 @@ function! s:prototype.build() return line endfunction +function! s:should_change_group(group1, group2) + if a:group1 == a:group2 + return 0 + endif + 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] || color1[0] != color2[0] + else + return color1[3] != color2[3] || color1[2] != color2[2] + endif +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 + if s:should_change_group(a:prev_group, a:group) 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.'#' + else + let line .= a:side ? a:self._context.left_alt_sep : a:self._context.right_alt_sep endif return line endfunction diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index ef05bbc5..17a6cf51 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -39,16 +39,6 @@ function! s:get_array(fg, bg, opts) \ : [ '', '', fg, bg, join(a:opts, ',') ] 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, ...) let fg = s:get_syn(a:group, 'fg') let bg = s:get_syn(a:group, 'bg') diff --git a/t/builder.vim b/t/builder.vim index 2b83d5a8..d82367ec 100644 --- a/t/builder.vim +++ b/t/builder.vim @@ -20,13 +20,22 @@ describe 'active builder' it 'should reuse highlight group if background colors match' highlight Foo1 ctermfg=1 ctermbg=2 - highlight Foo2 ctermfg=3 ctermbg=2 + highlight Foo2 ctermfg=1 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 + it 'should switch highlight groups if foreground colors differ' + highlight Foo1 ctermfg=1 ctermbg=2 + highlight Foo2 ctermfg=2 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%#Foo1_to_Foo2#>%#Foo2#world' + end + it 'should split left/right sections' call s:builder.split() let stl = s:builder.build()