feat: better buffer/window vars for terminal and float

This commit is contained in:
Folke Lemaitre 2024-11-04 11:14:45 +01:00
parent e2420fe847
commit 1abce78a8b
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 13 additions and 7 deletions

View file

@ -190,7 +190,11 @@ function M:open_win()
local vertical = position == "left" or position == "right"
if parent == 0 then
for _, win in ipairs(vim.api.nvim_list_wins()) do
if vim.w[win].snacks_float_relative == "editor" and vim.w[win].snacks_float_position == position then
if
vim.w[win].snacks_float
and vim.w[win].snacks_float.relative == "editor"
and vim.w[win].snacks_float.position == position
then
parent = win
relative = "win"
position = vertical and "bottom" or "right"
@ -210,9 +214,11 @@ function M:open_win()
vim.api.nvim_set_current_win(self.win)
end
end
vim.w[self.win].snacks_float = self.id
vim.w[self.win].snacks_float_position = self.opts.position
vim.w[self.win].snacks_float_relative = self.opts.win.relative
vim.w[self.win].snacks_float = {
id = self.id,
position = self.opts.position,
relative = self.opts.win.relative,
}
end
function M:show()

View file

@ -54,11 +54,11 @@ local terminals = {}
---@param cmd? string | string[]
---@param opts? snacks.terminal.Config
function M.open(cmd, opts)
local id = vim.v.count1
---@type snacks.terminal.Config
opts = Snacks.config.get("terminal", defaults, opts)
opts.float.position = opts.float.position or (cmd and "float" or "bottom")
opts.float.wo.winbar = opts.float.wo.winbar
or (opts.float.position == "float" and "" or (vim.v.count1 .. ": %{b:term_title}"))
opts.float.wo.winbar = opts.float.wo.winbar or (opts.float.position == "float" and "" or (id .. ": %{b:term_title}"))
if opts.override then
return opts.override(cmd, opts)
@ -69,7 +69,7 @@ function M.open(cmd, opts)
---@param self snacks.terminal
opts.float.on_buf = function(self)
self.cmd = cmd
vim.b[self.buf].snacks_terminal_cmd = cmd
vim.b[self.buf].snacks_terminal = { cmd = cmd, id = id }
if on_buf then
on_buf(self)
end