Improve section cache management
This commit is contained in:
@@ -9,7 +9,6 @@ local fmt = string.format
|
|||||||
local common = require('hardline.common')
|
local common = require('hardline.common')
|
||||||
local bufferline = require('hardline.bufferline')
|
local bufferline = require('hardline.bufferline')
|
||||||
local M = {}
|
local M = {}
|
||||||
local cache = {}
|
|
||||||
|
|
||||||
-------------------- OPTIONS -------------------------------
|
-------------------- OPTIONS -------------------------------
|
||||||
M.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 --------------------
|
-------------------- SECTION MANAGEMENT --------------------
|
||||||
local function aggregate_sections(sections)
|
local function aggregate_sections(sections)
|
||||||
local aggregated, piv = {}, 1
|
local aggregated, piv = {}, 1
|
||||||
@@ -147,18 +157,11 @@ function M.update_statusline()
|
|||||||
sections = remove_empty_sections(sections)
|
sections = remove_empty_sections(sections)
|
||||||
sections = aggregate_sections(sections)
|
sections = aggregate_sections(sections)
|
||||||
cache[g.statusline_winid] = sections
|
cache[g.statusline_winid] = sections
|
||||||
|
refresh_cache()
|
||||||
end
|
end
|
||||||
return table.concat(highlight_sections(sections))
|
return table.concat(highlight_sections(sections))
|
||||||
end
|
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 ----------------------------
|
-------------------- BUFFERLINE ----------------------------
|
||||||
function M.update_bufferline()
|
function M.update_bufferline()
|
||||||
local sections = {}
|
local sections = {}
|
||||||
|
|||||||
@@ -7,8 +7,3 @@ if exists('g:loaded_hardline')
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let g:loaded_hardline = 1
|
let g:loaded_hardline = 1
|
||||||
|
|
||||||
augroup hardline
|
|
||||||
autocmd!
|
|
||||||
autocmd WinClosed * lua require('hardline').clear_cache()
|
|
||||||
augroup END
|
|
||||||
|
|||||||
Reference in New Issue
Block a user