Skip to content

Commit

Permalink
fix(win_attr): improve behavior of get_win_attr; add cleanup to set_w…
Browse files Browse the repository at this point in the history
…in_attr
  • Loading branch information
rebelot committed Aug 31, 2022
1 parent 496b86b commit 8278dc8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lua/heirline/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,24 @@ function StatusLine:local_(attr)
return rawget(self, attr)
end

local function cleanup_win_attr(win_attr)
if not win_attr then
return
end
local nwin = #vim.api.nvim_tabpage_list_wins(0)
if #win_attr > nwin then
for i = nwin + 1, #win_attr do
win_attr[i] = nil
end
end
end

--- Set window-nr attribute
---@param attr string
---@param val any
---@param default any
function StatusLine:set_win_attr(attr, val, default)
cleanup_win_attr(self[attr])
local winnr = self.winnr
self[attr] = self[attr] or {}
self[attr][winnr] = val or (self[attr][winnr] or default)
Expand All @@ -164,7 +177,13 @@ end
---@return any
function StatusLine:get_win_attr(attr, default)
local winnr = self.winnr
self[attr] = self[attr] or {}
if not self[attr] then
if default then
self[attr] = {}
else
return
end
end
self[attr][winnr] = self[attr][winnr] or default
return self[attr][winnr]
end
Expand Down

0 comments on commit 8278dc8

Please sign in to comment.