mirror of
https://github.com/neovim/neovim.git
synced 2026-03-28 03:12:00 +00:00
fix(ui2): move windows to current tabpage
Problem: Windows are closed and re-opened after changing tabpage (and
might be removed from the current tabpage after 094b297a).
Solution: Ensure windows are on the current tabpage by moving them.
This commit is contained in:
@@ -51,22 +51,17 @@ local M = {
|
||||
},
|
||||
}
|
||||
|
||||
local tab = 0
|
||||
---Ensure target buffers and windows are still valid.
|
||||
function M.check_targets()
|
||||
local curtab = api.nvim_get_current_tabpage()
|
||||
for i, type in ipairs({ 'cmd', 'dialog', 'msg', 'pager' }) do
|
||||
local oldbuf = api.nvim_buf_is_valid(M.bufs[type]) and M.bufs[type]
|
||||
local oldwin, setopt = api.nvim_win_is_valid(M.wins[type]) and M.wins[type], not oldbuf
|
||||
M.bufs[type] = oldbuf or api.nvim_create_buf(false, false)
|
||||
local buf = api.nvim_buf_is_valid(M.bufs[type]) and M.bufs[type]
|
||||
local win = api.nvim_win_is_valid(M.wins[type]) and M.wins[type]
|
||||
local floating = win and api.nvim_win_get_config(win).zindex
|
||||
local setopt = not buf or not win or not floating
|
||||
M.bufs[type] = buf or api.nvim_create_buf(false, false)
|
||||
|
||||
if tab ~= curtab and oldwin then
|
||||
-- Ensure dynamically set window configuration (M.msg.set_pos()) is copied
|
||||
-- over when switching tabpage. TODO: move to tabpage instead after #35816.
|
||||
M.wins[type] = api.nvim_open_win(M.bufs[type], false, api.nvim_win_get_config(oldwin))
|
||||
api.nvim_win_close(oldwin, true)
|
||||
setopt = true
|
||||
elseif not oldwin or not api.nvim_win_get_config(M.wins[type]).zindex then
|
||||
if not win or not floating then
|
||||
-- Open a new window when closed or no longer floating (e.g. wincmd J).
|
||||
local cfg = { col = 0, row = 1, width = 10000, height = 1, mouse = false, noautocmd = true }
|
||||
cfg.focusable = false
|
||||
@@ -80,9 +75,11 @@ function M.check_targets()
|
||||
-- kZIndexMessages < cmd zindex < kZIndexCmdlinePopupMenu (grid_defs.h), pager below others.
|
||||
cfg.zindex = 201 - i
|
||||
M.wins[type] = api.nvim_open_win(M.bufs[type], false, cfg)
|
||||
setopt = true
|
||||
elseif api.nvim_win_get_buf(M.wins[type]) ~= M.bufs[type] then
|
||||
api.nvim_win_set_buf(M.wins[type], M.bufs[type])
|
||||
elseif api.nvim_win_get_tabpage(M.wins[type]) ~= curtab then
|
||||
api.nvim_win_set_config(M.wins[type], { win = api.nvim_tabpage_get_win(curtab) })
|
||||
end
|
||||
if win and floating and api.nvim_win_get_buf(win) ~= M.bufs[type] then
|
||||
api.nvim_win_set_buf(win, M.bufs[type])
|
||||
setopt = true
|
||||
end
|
||||
|
||||
@@ -125,7 +122,6 @@ function M.check_targets()
|
||||
end
|
||||
end
|
||||
end
|
||||
tab = curtab
|
||||
end
|
||||
|
||||
local function ui_callback(redraw_msg, event, ...)
|
||||
@@ -221,16 +217,6 @@ function M.enable(opts)
|
||||
end,
|
||||
desc = 'Set cmdline and message window dimensions after shell resize or tabpage change.',
|
||||
})
|
||||
|
||||
api.nvim_create_autocmd('WinEnter', {
|
||||
callback = function()
|
||||
local win = api.nvim_get_current_win()
|
||||
if vim.tbl_contains(M.wins, win) and api.nvim_win_get_config(win).hide then
|
||||
vim.cmd.wincmd('p')
|
||||
end
|
||||
end,
|
||||
desc = 'Make sure hidden UI window is never current.',
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user