Skip to content

Commit

Permalink
fix(update): dont set _win_cache during component eval (#79)
Browse files Browse the repository at this point in the history
Set _win_cache only once at the end of the main evaluation loop
(_freeze_cache).
  • Loading branch information
rebelot committed Oct 30, 2022
1 parent 712f39c commit db41ad4
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lua/heirline/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,14 @@ function StatusLine:_eval()
end

if update then
self:set_win_attr("_win_cache", tree)
tbl_insert(self._updatable_components, self)
end
return true
end

---private
---Traverse a nested tree and return the flattened tree
---@param tree table
---@param tree table
---@param flat_tree? table
---@return table
local function traverse(tree, flat_tree)
Expand All @@ -380,7 +379,7 @@ end
function StatusLine:traverse()
local tree = rawget(self, "_tree")
local flat_tree = traverse(tree)
return table.concat(flat_tree, "")
return tbl_concat(flat_tree, "")
end

--- Empty the component tree leaving its reference intact
Expand All @@ -397,8 +396,7 @@ end
-- this MUST be called at the end of the main loop
function StatusLine:_freeze_cache()
for _, component in ipairs(self._updatable_components) do
local win_cache = component:get_win_attr("_win_cache") -- check nil?
local fixed_cache = component:traverse(win_cache)
local fixed_cache = component:traverse()
component:set_win_attr("_win_cache", fixed_cache)
component:clear_tree()
component._tree[1] = fixed_cache
Expand Down

0 comments on commit db41ad4

Please sign in to comment.