diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim index 5f1d8e4a..f69752e7 100644 --- a/autoload/airline/builder.vim +++ b/autoload/airline/builder.vim @@ -23,12 +23,17 @@ function! s:prototype.add_section(group, contents) let self._line .= '%#'.a:group.'#' endif - let accent = matchstr(a:contents, 'airline_accent_\zs[^#]*\ze') - let contents = substitute(a:contents, 'airline_accent', a:group, 'g') - if contents != a:contents + let contents = [] + let content_parts = split(a:contents, 'airline_accent') + for cpart in content_parts + let accent = matchstr(cpart, '_\zs[^#]*\ze') call airline#highlighter#add_accent(a:group, accent) - endif - let self._line .= contents + call add(contents, cpart) + endfor + let line = join(contents, a:group) + let line = substitute(line, '__restore__', a:group, 'g') + + let self._line .= line let self._curgroup = a:group endfunction diff --git a/autoload/airline/section.vim b/autoload/airline/section.vim index e56b09a4..ef1e0431 100644 --- a/autoload/airline/section.vim +++ b/autoload/airline/section.vim @@ -49,6 +49,9 @@ function! s:create(parts, append) endif let val .= partval + if exists('part.accent') + let val .= '%#__restore__#' + endif let _ .= val endfor return _ diff --git a/t/builder.vim b/t/builder.vim index 705abfb8..07df4b8c 100644 --- a/t/builder.vim +++ b/t/builder.vim @@ -44,6 +44,19 @@ describe 'active builder' let stl = s:builder.build() Expect stl == '%#Normal#%#Normal_foo#hello' end + + it 'should replace two accent groups with correct groups' + call s:builder.add_section('Normal', '%#airline_accent_foo#hello%#airline_accent_bar#world') + let stl = s:builder.build() + Expect stl =~ '%#Normal_foo#hello%#Normal_bar#world' + end + + it 'should special restore group should go back to previous group' + call s:builder.add_section('Normal', '%#__restore__#') + let stl = s:builder.build() + Expect stl !~ '%#__restore__#' + Expect stl =~ '%#Normal#' + end end describe 'inactive builder' diff --git a/t/init.vim b/t/init.vim index a20bc334..b9f8fb6f 100644 --- a/t/init.vim +++ b/t/init.vim @@ -28,7 +28,7 @@ describe 'init' end it 'section c should be file' - Expect g:airline_section_c == '%<%f%m %#airline_accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}' + Expect g:airline_section_c == '%<%f%m %#airline_accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#' end it 'section x should be filetype'