feat(win): make split window "stacking" configurable

This commit is contained in:
Folke Lemaitre 2025-10-21 16:04:17 +02:00
parent ee0de23301
commit e46a09427c
No known key found for this signature in database
GPG key ID: 9B52594D560070AB

View file

@ -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