Skip to content

Commit 6f8f4cf

Browse files
authored
fix: error when passing bufnr to popup.create() (#3)
1 parent 8f128cc commit 6f8f4cf

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lua/popup/init.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,17 @@ function popup.create(what, vim_options)
162162
-- maxwidth Maximum width of the contents, excluding border, padding and scrollbar.
163163
-- minwidth Minimum width of the contents, excluding border, padding and scrollbar.
164164
local width = vim_options.width or 1
165-
for _, v in ipairs(what) do
166-
width = math.max(width, #v)
165+
local height
166+
if type(what) == 'number' then
167+
height = vim.api.nvim_buf_line_count(what)
168+
else
169+
for _, v in ipairs(what) do
170+
width = math.max(width, #v)
171+
end
172+
height = #what
167173
end
168174
win_opts.width = utils.bounded(width, vim_options.minwidth, vim_options.maxwidth)
169-
win_opts.height = utils.bounded(#what, vim_options.minheight, vim_options.maxheight)
175+
win_opts.height = utils.bounded(height, vim_options.minheight, vim_options.maxheight)
170176

171177
-- textprop, When present the popup is positioned next to a text
172178
-- , property with this name and will move when the text

lua/tests/basic_popup_spec.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,13 @@ if test_level == 8 then
8080
-- border = { 1, 1, 1, 1 }
8181
})
8282
end
83+
84+
if test_level == 9 then
85+
local bufnr = vim.api.nvim_create_buf(false, false)
86+
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {'pass bufnr 1', 'pass bufnr 2'})
87+
popup.create(bufnr, {
88+
line = 8,
89+
col = 55,
90+
minwidth = 20,
91+
})
92+
end

0 commit comments

Comments
 (0)