feat(api): allow passing options to float so it can be used outside of lazy

This commit is contained in:
Folke Lemaitre 2022-12-30 10:23:12 +01:00
parent d205cd45d0
commit 2a617a7024
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 6 additions and 4 deletions

View File

@ -84,10 +84,10 @@ function M.throttle(ms, fn)
end
---@param cmd string[]
---@param opts? {cwd:string, filetype:string, terminal?:boolean, close_on_exit?:boolean, enter?:boolean}
---@param opts? {cwd:string, filetype:string, terminal?:boolean, close_on_exit?:boolean, enter?:boolean, float?:LazyViewOptions}
function M.open_cmd(cmd, opts)
opts = opts or {}
local float = M.float()
local float = M.float(opts.float)
if opts.filetype then
vim.bo[float.buf].filetype = opts.filetype

View File

@ -6,6 +6,7 @@ local ViewConfig = require("lazy.view.config")
---@field file? string
---@field margin? {top?:number, right?:number, bottom?:number, left?:number}
---@field win_opts LazyViewWinOpts
---@field size? {width:number, height:number}
local defaults = {
win_opts = {},
}
@ -32,6 +33,7 @@ end
---@param opts? LazyViewOptions
function M:init(opts)
self.opts = vim.tbl_deep_extend("force", defaults, opts or {})
self.opts.size = vim.tbl_extend("keep", self.opts.size or {}, Config.options.ui.size)
self:mount()
self:on_key(ViewConfig.keys.close, self.close)
self:on({ "BufDelete", "BufLeave", "BufHidden" }, self.close, { once = true })
@ -42,8 +44,8 @@ function M:layout()
local function size(max, value)
return value > 1 and math.min(value, max) or math.floor(max * value)
end
self.opts.win_opts.width = size(vim.o.columns, Config.options.ui.size.width)
self.opts.win_opts.height = size(vim.o.lines, Config.options.ui.size.height)
self.opts.win_opts.width = size(vim.o.columns, self.opts.size.width)
self.opts.win_opts.height = size(vim.o.lines, self.opts.size.height)
self.opts.win_opts.row = math.floor((vim.o.lines - self.opts.win_opts.height) / 2)
self.opts.win_opts.col = math.floor((vim.o.columns - self.opts.win_opts.width) / 2)