Remove hidden sections before reloading

This commit is contained in:
Olivier Roques
2020-12-28 13:53:09 +01:00
parent 2cb26dba5b
commit 1076f7f317
2 changed files with 14 additions and 5 deletions

View File

@@ -33,8 +33,9 @@ M.options = {
function M.update_statusline()
local cache = M.options.sections
if common.is_active() then
cache = statusline.remove_hidden_sections(cache)
cache = statusline.reload_sections(cache)
cache = statusline.filter_sections(cache)
cache = statusline.remove_empty_sections(cache)
cache = statusline.aggregate_sections(cache)
api.nvim_win_set_var(g.statusline_winid, 'hardline_cache', cache)
else

View File

@@ -25,10 +25,10 @@ local function aggregate_sections(sections)
return aggregated
end
local function filter_sections(sections)
local function remove_empty_sections(sections)
local function filter(section)
if type(section) == 'string' then return section ~= '' end
return section.hide <= fn.winwidth(0) and section.item ~= ''
if type(section) == 'table' then return section.item ~= '' end
return section ~= ''
end
return vim.tbl_filter(filter, sections)
end
@@ -52,8 +52,16 @@ local function reload_sections(sections)
return vim.tbl_map(map, sections)
end
local function remove_hidden_sections(sections)
local function filter(section)
return not section.hide or section.hide <= fn.winwidth(0)
end
return vim.tbl_filter(filter, sections)
end
return {
aggregate_sections = aggregate_sections,
filter_sections = filter_sections,
remove_empty_sections = remove_empty_sections,
reload_sections = reload_sections,
remove_hidden_sections = remove_hidden_sections,
}