From 7a552f415c48aed33bf7eaa3c50e78504d417913 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Thu, 5 Dec 2024 06:49:09 +0100 Subject: [PATCH] highlighter: remove stale separator entries on buffer unload fixes: #2701 Co-authored-by: Mina Nagy Zaki Signed-off-by: Christian Brabandt --- autoload/airline/highlighter.vim | 16 +++++++++++++++- plugin/airline.vim | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index a9151009..2efca60d 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -186,6 +186,13 @@ if !exists(":def") || !airline#util#has_vim9_script() call exec_separator({}, a:from, a:to, a:inverse, '') endfunction + function! airline#highlighter#remove_separators_for_bufnr(bufnr) abort + " remove all separators, that have the buffer number in their name, + " but do not be too greedy! + let pat = 'c' . a:bufnr . '\(\D\|$\)' + call filter(s:separators, 'v:key !~# pat') + endfunction + function! s:exec_separator(dict, from, to, inverse, suffix) abort if pumvisible() return @@ -529,6 +536,13 @@ else s:exec_separator({}, from, to, inverse, '') enddef + def airline#highlighter#remove_separators_for_bufnr(bufnr: string): void + # remove all separators, that have the bufnr in its name, make sure we + # have a full match here + const pat = $'c{bufnr}\(\D\|$\)' + filter(s:separators, (k, v) => k !~# pat) + enddef + def s:exec_separator(dict: dict, from_arg: string, to_arg: string, inverse: bool, suffix: string): void if pumvisible() return @@ -681,5 +695,5 @@ else endfor endif endfor - enddef + enddef endif diff --git a/plugin/airline.vim b/plugin/airline.vim index 17374b3f..7869be05 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -48,6 +48,7 @@ function! s:init() endfunction let s:active_winnr = -1 + function! s:on_window_changed(event) " don't trigger for Vim popup windows if &buftype is# 'popup' @@ -67,11 +68,20 @@ function! s:on_window_changed(event) \ && &ft !~? 'gitcommit' " fugitive is special, it changes names and filetypes several times, " make sure the caching does not get into its way + if a:event ==# 'BufUnload' + " in the BufUnload event, make sure the cacheing does not prevent + " removing stale entries + call airline#highlighter#remove_separators_for_bufnr(expand('')) + endif return endif let g:airline_last_window_changed = l:key call s:init() call airline#update_statusline() + + if a:event ==# 'BufUnload' + call airline#highlighter#remove_separators_for_bufnr(expand('')) + endif endfunction function! s:on_focus_gained()