Skip to content

Commit 2a617a7

Browse files
committedDec 30, 2022
feat(api): allow passing options to float so it can be used outside of lazy
1 parent d205cd4 commit 2a617a7

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
 

‎lua/lazy/util.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ function M.throttle(ms, fn)
8484
end
8585

8686
---@param cmd string[]
87-
---@param opts? {cwd:string, filetype:string, terminal?:boolean, close_on_exit?:boolean, enter?:boolean}
87+
---@param opts? {cwd:string, filetype:string, terminal?:boolean, close_on_exit?:boolean, enter?:boolean, float?:LazyViewOptions}
8888
function M.open_cmd(cmd, opts)
8989
opts = opts or {}
90-
local float = M.float()
90+
local float = M.float(opts.float)
9191

9292
if opts.filetype then
9393
vim.bo[float.buf].filetype = opts.filetype

‎lua/lazy/view/float.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local ViewConfig = require("lazy.view.config")
66
---@field file? string
77
---@field margin? {top?:number, right?:number, bottom?:number, left?:number}
88
---@field win_opts LazyViewWinOpts
9+
---@field size? {width:number, height:number}
910
local defaults = {
1011
win_opts = {},
1112
}
@@ -32,6 +33,7 @@ end
3233
---@param opts? LazyViewOptions
3334
function M:init(opts)
3435
self.opts = vim.tbl_deep_extend("force", defaults, opts or {})
36+
self.opts.size = vim.tbl_extend("keep", self.opts.size or {}, Config.options.ui.size)
3537
self:mount()
3638
self:on_key(ViewConfig.keys.close, self.close)
3739
self:on({ "BufDelete", "BufLeave", "BufHidden" }, self.close, { once = true })
@@ -42,8 +44,8 @@ function M:layout()
4244
local function size(max, value)
4345
return value > 1 and math.min(value, max) or math.floor(max * value)
4446
end
45-
self.opts.win_opts.width = size(vim.o.columns, Config.options.ui.size.width)
46-
self.opts.win_opts.height = size(vim.o.lines, Config.options.ui.size.height)
47+
self.opts.win_opts.width = size(vim.o.columns, self.opts.size.width)
48+
self.opts.win_opts.height = size(vim.o.lines, self.opts.size.height)
4749
self.opts.win_opts.row = math.floor((vim.o.lines - self.opts.win_opts.height) / 2)
4850
self.opts.win_opts.col = math.floor((vim.o.columns - self.opts.win_opts.width) / 2)
4951

0 commit comments

Comments
 (0)