From 1076f7f317e71e037fffa36c55932191ec05f258 Mon Sep 17 00:00:00 2001 From: Olivier Roques Date: Mon, 28 Dec 2020 13:53:09 +0100 Subject: [PATCH] Remove hidden sections before reloading --- lua/hardline.lua | 3 ++- lua/hardline/statusline.lua | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lua/hardline.lua b/lua/hardline.lua index 72ca03e..a983487 100644 --- a/lua/hardline.lua +++ b/lua/hardline.lua @@ -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 diff --git a/lua/hardline/statusline.lua b/lua/hardline/statusline.lua index e432a7d..f312b29 100644 --- a/lua/hardline/statusline.lua +++ b/lua/hardline/statusline.lua @@ -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, }