highlighter: Only recreate hi groups for visible buffers

In a long editing session, there could happen to accumulate several
highlighting groups for buffers that might no longer be visible.

Therefore, only re-create the highlighting group for buffers that are
actually displayed in the current tabpage. If not, skip them.

references #1779
This commit is contained in:
Christian Brabandt 2018-11-08 12:17:40 +01:00
parent a334a89e59
commit 09b5eb952c
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -236,6 +236,10 @@ function! airline#highlighter#highlight(modes, ...)
let mapped = map(a:modes, 'v:val == a:modes[0] ? v:val : a:modes[0]."_".v:val')
let suffix = a:modes[0] == 'inactive' ? '_inactive' : ''
let airline_grouplist = []
let buffers_in_tabpage = sort(tabpagebuflist())
if exists("*uniq")
let buffers_in_tabpage = uniq(buffers_in_tabpage)
endif
" mapped might be something like ['normal', 'normal_modified']
" if a group is in both modes available, only define the second
" that is how this was done previously overwrite the previous definition
@ -248,6 +252,14 @@ function! airline#highlighter#highlight(modes, ...)
if name is# 'airline_c' && !empty(bufnr) && suffix is# '_inactive'
let name = 'airline_c'.bufnr
endif
" do not re-create highlighting for buffers that are no longer visible
" in the current tabpage
if name[0:8] is# 'airline_c'
let bnr = matchstr(name, 'airline_c\\zs\d\+') + 0
if index(buffers_in_tabpage, bnr) == -1
continue
endif
endif
if s:group_not_done(airline_grouplist, name.suffix)
call airline#highlighter#exec(name.suffix, mode_colors)
endif