Improve section cache management

This commit is contained in:
Olivier Roques
2021-05-22 01:06:33 +02:00
parent cbdba2dcb9
commit e14451627f
2 changed files with 12 additions and 14 deletions

View File

@@ -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 = {}