diff --git a/lua/hardline.lua b/lua/hardline.lua index f2d1154..f34cfe3 100644 --- a/lua/hardline.lua +++ b/lua/hardline.lua @@ -9,7 +9,6 @@ local fmt = string.format local common = require('hardline.common') local bufferline = require('hardline.bufferline') local M = {} -local cache = {} -------------------- OPTIONS ------------------------------- M.options = { @@ -34,6 +33,17 @@ M.options = { }, } +-------------------- SECTION CACHE ------------------------- +local cache = {} + +local function refresh_cache() + for winid, _ in pairs(cache) do + if fn.win_id2win(winid) == 0 then + cache[winid] = nil + end + end +end + -------------------- SECTION MANAGEMENT -------------------- local function aggregate_sections(sections) local aggregated, piv = {}, 1 @@ -147,18 +157,11 @@ function M.update_statusline() sections = remove_empty_sections(sections) sections = aggregate_sections(sections) cache[g.statusline_winid] = sections + refresh_cache() end return table.concat(highlight_sections(sections)) end -function M.clear_cache() - for winid, _ in pairs(cache) do - if fn.win_id2win(winid) == 0 then - cache[winid] = nil - end - end -end - -------------------- BUFFERLINE ---------------------------- function M.update_bufferline() local sections = {} diff --git a/plugin/hardline.vim b/plugin/hardline.vim index b3e5baf..c24cddc 100644 --- a/plugin/hardline.vim +++ b/plugin/hardline.vim @@ -7,8 +7,3 @@ if exists('g:loaded_hardline') endif let g:loaded_hardline = 1 - -augroup hardline - autocmd! - autocmd WinClosed * lua require('hardline').clear_cache() -augroup END