Skip to content

Commit

Permalink
feat: better buffer/window vars for terminal and float
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 4, 2024
1 parent e2420fe commit 1abce78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions lua/snacks/float.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions lua/snacks/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 1abce78

Please sign in to comment.