mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
feat(win): make split window "stacking" configurable
This commit is contained in:
parent
ee0de23301
commit
e46a09427c
1 changed files with 7 additions and 2 deletions
|
|
@ -83,6 +83,7 @@ M.meta = {
|
|||
---@field text? string|string[]|fun():(string[]|string) Initial lines to set in the buffer
|
||||
---@field actions? table<string, snacks.win.Action.spec> Actions that can be used in key mappings
|
||||
---@field resize? boolean Automatically resize the window when the editor is resized
|
||||
---@field stack? boolean When enabled, multiple split windows with the same position will be stacked together (useful for terminals)
|
||||
local defaults = {
|
||||
show = true,
|
||||
fixbuf = true,
|
||||
|
|
@ -701,15 +702,18 @@ function M:open_win()
|
|||
elseif position == "current" then
|
||||
self.win = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_buf(self.win, self.buf)
|
||||
else
|
||||
else --split
|
||||
local parent = self.opts.win and vim.api.nvim_win_is_valid(self.opts.win) and self.opts.win or 0
|
||||
local vertical = position == "left" or position == "right"
|
||||
if parent == 0 then
|
||||
-- When stacking is enabled, find an existing window with the same relative/position
|
||||
-- and stack the new window perpendicular to it instead of creating a new split
|
||||
if parent == 0 and self.opts.stack then
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
if
|
||||
vim.w[win].snacks_win
|
||||
and vim.w[win].snacks_win.relative == relative
|
||||
and vim.w[win].snacks_win.position == position
|
||||
and vim.w[win].snacks_win.stack == true
|
||||
then
|
||||
parent = win
|
||||
relative = "win"
|
||||
|
|
@ -737,6 +741,7 @@ function M:open_win()
|
|||
id = self.id,
|
||||
position = self.opts.position,
|
||||
relative = self.opts.relative,
|
||||
stack = self.opts.stack,
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue