Improve section cache management
This commit is contained in:
@@ -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 = {}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user