fix(notifier): take title/footer into account to determine notification width. Fixes #54

This commit is contained in:
Folke Lemaitre 2024-11-11 11:07:26 +01:00
parent 3aec3b2536
commit 09a6f17ecc
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 28 additions and 2 deletions

View file

@ -492,10 +492,13 @@ function N:render(notif)
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
local pad = self.opts.padding and (win:add_padding() or 2) or 0
local width = 0
local width = win:border_text_width()
for _, line in ipairs(lines) do
width = math.max(width, vim.fn.strdisplaywidth(line) + pad)
end
if win.opts.border and win.opts.border ~= "none" and win.opts.border ~= "" then
width = width + 2
end
width = dim(width, self.opts.width.min, self.opts.width.max, vim.o.columns)
local height = #lines

View file

@ -507,13 +507,36 @@ function M:size()
local opts = self:win_opts()
local height = opts.height
local width = opts.width
if opts.border and opts.border ~= "none" then
if self:has_border() then
height = height + 2
width = width + 2
end
return { height = height, width = width }
end
function M:has_border()
return self.opts.border and self.opts.border ~= "" and self.opts.border ~= "none"
end
function M:border_text_width()
if not self:has_border() then
return 0
end
local ret = 0
for _, t in ipairs({ "title", "footer" }) do
local str = self.opts[t] or {}
str = type(str) == "string" and { str } or str
---@cast str (string|string[])[]
ret = math.max(ret, #table.concat(
vim.tbl_map(function(s)
return type(s) == "string" and s or s[1]
end, str),
""
))
end
return ret
end
---@private
---@param type "win" | "buf"
function M:set_options(type)