mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 11:18:26 +00:00
fix(win): better way of finding a main window when fixbuf is true
This commit is contained in:
parent
2ff8ce0208
commit
84ee7ddf54
1 changed files with 15 additions and 8 deletions
|
@ -810,17 +810,24 @@ function M:show()
|
|||
|
||||
-- another buffer was opened in this window
|
||||
-- find another window to swap with
|
||||
local main ---@type number?
|
||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||
if win ~= self.win and vim.bo[vim.api.nvim_win_get_buf(win)].buftype == "" then
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_win_set_buf(self.win, self.buf)
|
||||
vim.api.nvim_win_set_buf(win, buf)
|
||||
vim.api.nvim_set_current_win(win)
|
||||
vim.cmd.stopinsert()
|
||||
end)
|
||||
return
|
||||
local is_float = vim.api.nvim_win_get_config(win).relative ~= ""
|
||||
if not is_float then
|
||||
main = win
|
||||
if win ~= self.win and vim.bo[vim.api.nvim_win_get_buf(win)].buftype == "" then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if main then
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_win_set_buf(self.win, self.buf)
|
||||
vim.api.nvim_win_set_buf(main, buf)
|
||||
vim.api.nvim_set_current_win(main)
|
||||
vim.cmd.stopinsert()
|
||||
end)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue