Skip to content

Commit 4429ebb

Browse files
committed
Redefine highlights on colorscheme changes
This will ensure that they get updated to match the new color definitions.
1 parent 316fd37 commit 4429ebb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

autoload/coverage.vim

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ endif
2727
if !exists('s:coverage_states')
2828
let s:coverage_states = ['covered', 'uncovered', 'partial']
2929
endif
30+
let s:highlights_defined = 0
3031

3132
"}}}
3233

@@ -46,17 +47,15 @@ endfunction
4647
" Defines highlighting rules for coverage colors and defines text signs for each
4748
" coverage state, as defined via plugin flags. See |coverage-config|.
4849
function! s:DefineHighlighting() abort
49-
if !hlexists('coverage_covered')
50-
for l:state in s:coverage_states
51-
execute 'highlight coverage_' . l:state .
50+
for l:state in s:coverage_states
51+
execute 'highlight coverage_' . l:state .
5252
\ ' ctermbg=' . s:plugin.Flag(l:state . '_ctermbg') .
5353
\ ' ctermfg=' . s:plugin.Flag(l:state . '_ctermfg') .
5454
\ ' guibg=' . s:plugin.Flag(l:state . '_guibg') .
5555
\ ' guifg=' . s:plugin.Flag(l:state . '_guifg')
56-
execute 'sign define sign_' . l:state . ' text=' .
56+
execute 'sign define sign_' . l:state . ' text=' .
5757
\ s:plugin.Flag(l:state . '_text') . ' texthl=coverage_' . l:state
58-
endfor
59-
endif
58+
endfor
6059
endfunction
6160

6261

@@ -67,7 +66,9 @@ endfunction
6766
" @default show_stats=1
6867
function! s:RenderFromCache(filename, ...) abort
6968
let l:show_stats = maktaba#ensure#IsBool(get(a:, 1, 1))
70-
call s:DefineHighlighting()
69+
if !s:highlights_defined
70+
call s:DefineHighlighting()
71+
endif
7172
if (has_key(s:cache, a:filename))
7273
let l:data = s:cache[a:filename]
7374
for l:state in s:coverage_states
@@ -314,4 +315,12 @@ function! coverage#EnsureProvider(provider) abort
314315
endif
315316
endfunction
316317

318+
319+
""
320+
" Re-define highlights after the colorscheme was changed.
321+
augroup coverage_highlights
322+
au!
323+
autocmd ColorScheme * if s:defined_highlights | call s:DefineHighlighting() | endif
324+
augroup END
325+
317326
"}}}

0 commit comments

Comments
 (0)