Skip to content

Commit

Permalink
fix(flexible_components): better checking of maximum available space
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelot committed Aug 29, 2022
1 parent ad4ddf4 commit 3ea10b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
5 changes: 3 additions & 2 deletions lua/heirline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ local function _eval(statusline, full_width)
if buflist then
out = statusline:traverse() -- this is now the tabline, after expansion/contraction
-- the space to render the buflist is "columns - (all_minus_fullwidthbuflist)"
buflist._maxwidth = vim.o.columns - (utils.count_chars(out) - utils.count_chars(buflist:traverse()))
utils.page_buflist(buflist)
local maxwidth = (full_width and vim.o.columns) or vim.api.nvim_win_get_width(0)
maxwidth = maxwidth - (utils.count_chars(out) - utils.count_chars(buflist:traverse()))
utils.page_buflist(buflist, maxwidth)
out = statusline:traverse()

-- now the buflist is paged, and flexible components still have the same value, however, there might be more space now, depending on the page
Expand Down
10 changes: 2 additions & 8 deletions lua/heirline/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,7 @@ function M.expand_or_contract_flexible_components(flexible_components, full_widt
return
end

local winw
if full_width then
winw = vim.o.columns
else
winw = vim.api.nvim_win_get_width(0)
end
local winw = (full_width and vim.o.columns) or vim.api.nvim_win_get_width(0)

local stl_len = M.count_chars(out)

Expand Down Expand Up @@ -434,13 +429,12 @@ end

--- Private function
---@param buflist table
function M.page_buflist(buflist)
function M.page_buflist(buflist, maxwidth)
if not buflist or #buflist == 0 then
return
end

local tbl = {}
local maxwidth = buflist._maxwidth or vim.o.columns
maxwidth = maxwidth - 2 -- leave some space for {right,left}_trunc

local pages = {}
Expand Down

0 comments on commit 3ea10b6

Please sign in to comment.