mirror of
https://github.com/lewis6991/gitsigns.nvim
synced 2025-04-17 12:47:02 +00:00
53 lines
1.2 KiB
Lua
Generated
53 lines
1.2 KiB
Lua
Generated
local popup = {}
|
|
|
|
local api = vim.api
|
|
|
|
local function bufnr_calc_width(buf, lines)
|
|
return api.nvim_buf_call(buf, function()
|
|
local width = 0
|
|
for _, l in ipairs(lines) do
|
|
local len = vim.fn.strdisplaywidth(l)
|
|
if len > width then
|
|
width = len
|
|
end
|
|
end
|
|
return width + 1
|
|
end)
|
|
end
|
|
|
|
function popup.create(lines, opts)
|
|
local ts = api.nvim_buf_get_option(0, 'tabstop')
|
|
local bufnr = api.nvim_create_buf(false, true)
|
|
assert(bufnr, "Failed to create buffer")
|
|
|
|
|
|
api.nvim_buf_set_option(bufnr, 'modifiable', true)
|
|
|
|
api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
|
|
|
|
api.nvim_buf_set_option(bufnr, 'modifiable', false)
|
|
|
|
|
|
|
|
api.nvim_buf_set_option(bufnr, 'tabstop', ts)
|
|
|
|
local opts1 = vim.deepcopy(opts or {})
|
|
opts1.height = opts1.height or #lines
|
|
opts1.width = opts1.width or bufnr_calc_width(bufnr, lines)
|
|
|
|
local win_id = api.nvim_open_win(bufnr, false, opts1)
|
|
|
|
if opts1.style == 'minimal' then
|
|
|
|
|
|
api.nvim_win_set_option(win_id, 'signcolumn', 'no')
|
|
end
|
|
|
|
vim.cmd("autocmd CursorMoved,CursorMovedI,BufLeave <buffer> ++once lua pcall(vim.api.nvim_win_close, " ..
|
|
win_id .. ", true)")
|
|
|
|
return win_id, bufnr
|
|
end
|
|
|
|
return popup
|