mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 19:28:24 +00:00
feat(win): added opts.fixbuf
to configure fixed window buffers
This commit is contained in:
parent
0409f7b878
commit
1f74d1ce77
1 changed files with 13 additions and 1 deletions
|
@ -35,8 +35,10 @@ local M = setmetatable({}, {
|
||||||
---@field keys? table<string, false|string|fun(self: snacks.win)|snacks.win.Keys> Key mappings
|
---@field keys? table<string, false|string|fun(self: snacks.win)|snacks.win.Keys> Key mappings
|
||||||
---@field on_buf? fun(self: snacks.win) Callback after opening the buffer
|
---@field on_buf? fun(self: snacks.win) Callback after opening the buffer
|
||||||
---@field on_win? fun(self: snacks.win) Callback after opening the window
|
---@field on_win? fun(self: snacks.win) Callback after opening the window
|
||||||
|
---@field fixbuf? boolean don't allow other buffers to be opened in this window
|
||||||
local defaults = {
|
local defaults = {
|
||||||
show = true,
|
show = true,
|
||||||
|
fixbuf = true,
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
position = "float",
|
position = "float",
|
||||||
minimal = true,
|
minimal = true,
|
||||||
|
@ -419,7 +421,6 @@ function M:show()
|
||||||
-- and it's the current window
|
-- and it's the current window
|
||||||
vim.api.nvim_create_autocmd("WinClosed", {
|
vim.api.nvim_create_autocmd("WinClosed", {
|
||||||
group = self.augroup,
|
group = self.augroup,
|
||||||
buffer = self.buf,
|
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
if ev.buf == self.buf and vim.api.nvim_get_current_win() == self.win then
|
if ev.buf == self.buf and vim.api.nvim_get_current_win() == self.win then
|
||||||
pcall(vim.cmd.wincmd, "p")
|
pcall(vim.cmd.wincmd, "p")
|
||||||
|
@ -439,13 +440,24 @@ function M:show()
|
||||||
vim.api.nvim_create_autocmd("BufWinEnter", {
|
vim.api.nvim_create_autocmd("BufWinEnter", {
|
||||||
group = self.augroup,
|
group = self.augroup,
|
||||||
callback = function()
|
callback = function()
|
||||||
|
-- window closes, so delete the autocmd
|
||||||
if not self:win_valid() then
|
if not self:win_valid() then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local buf = vim.api.nvim_win_get_buf(self.win)
|
local buf = vim.api.nvim_win_get_buf(self.win)
|
||||||
|
|
||||||
|
-- same buffer
|
||||||
if buf == self.buf then
|
if buf == self.buf then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- don't swap if fixbuf is disabled
|
||||||
|
if self.opts.fixbuf == false then
|
||||||
|
self.buf = buf
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- another buffer was opened in this window
|
-- another buffer was opened in this window
|
||||||
-- find another window to swap with
|
-- find another window to swap with
|
||||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue