Skip to content

Commit

Permalink
feat: sidebar.get_width() utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
willothy committed Jul 16, 2023
1 parent 368cd3e commit 5c46b21
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lua/cokeline/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ local bo = vim.bo
local fn = vim.fn
local o = vim.o

local width_cache = {}

local get_win = function(side)
local layout = fn.winlayout()

-- If the first split level is not given by vertically split windows we
-- return early.
-- return early and invalidate the width cache.
if layout[1] ~= "row" then
width_cache = {}
return nil
end

Expand Down Expand Up @@ -52,6 +55,7 @@ local get_win = function(side)
if win and win[1] == "leaf" then
winid = win[2]
else
width_cache[side] = nil
return nil
end
end
Expand All @@ -63,10 +67,12 @@ local get_win = function(side)
if win and win[1] == "leaf" then
winid = win[2]
else
width_cache[side] = nil
return nil
end
end
end
width_cache[side] = api.nvim_win_get_width(winid)
return winid
end

Expand Down Expand Up @@ -147,4 +153,8 @@ end
return {
get_win = get_win,
get_components = get_components,
---@return integer
get_width = function(side)
return width_cache[side] or 0
end,
}

0 comments on commit 5c46b21

Please sign in to comment.