refactor(#2826): get_winid returns new after consistency check

This commit is contained in:
Alexander Courtis 2025-06-20 10:01:12 +10:00
parent 3615c7dffe
commit 09ec00c085
2 changed files with 9 additions and 4 deletions

View File

@ -539,6 +539,7 @@ end
---@param opts table|nil ---@param opts table|nil
---@return boolean ---@return boolean
function View:is_visible(opts) function View:is_visible(opts)
-- TODO multi-instance rewrite and consistency check
if opts and opts.tabpage then if opts and opts.tabpage then
if globals.TABPAGES[opts.tabpage] == nil then if globals.TABPAGES[opts.tabpage] == nil then
return false return false
@ -618,10 +619,10 @@ function View:winid(tabpage, callsite)
local msg = string.format("View:winid(%3s, %-20.20s)", tabpage, callsite) local msg = string.format("View:winid(%3s, %-20.20s)", tabpage, callsite)
if bufnr then if bufnr then
for _, w in pairs(vim.api.nvim_tabpage_list_wins(tabpage or 0)) do for _, winid in pairs(vim.api.nvim_tabpage_list_wins(tabpage or 0)) do
if vim.api.nvim_win_get_buf(w) == bufnr then if vim.api.nvim_win_get_buf(winid) == bufnr then
log.line("dev", "%s b%d : w%s", msg, bufnr, w) log.line("dev", "%s b%d : w%s", msg, bufnr, winid)
return w return winid
end end
end end
else else
@ -669,6 +670,8 @@ function View:get_winid(tabpage, callsite)
if winid ~= tabinfo_winid then if winid ~= tabinfo_winid then
notify.error(msg) notify.error(msg)
end end
return winid
end end
-- legacy codepath -- legacy codepath
@ -712,6 +715,7 @@ function View:prevent_buffer_override()
local curbuf = vim.api.nvim_win_get_buf(curwin) local curbuf = vim.api.nvim_win_get_buf(curwin)
local bufname = vim.api.nvim_buf_get_name(curbuf) local bufname = vim.api.nvim_buf_get_name(curbuf)
--- TODO multi-instance this can be removed as winid() will handle it
if not bufname:match("NvimTree") then if not bufname:match("NvimTree") then
for i, tabpage in ipairs(globals.TABPAGES) do for i, tabpage in ipairs(globals.TABPAGES) do
if tabpage.winid == view_winid then if tabpage.winid == view_winid then

View File

@ -135,6 +135,7 @@ function M.open(opts)
open_view_and_draw() open_view_and_draw()
end end
-- TODO multi-instance is this actually necessary?
if explorer then if explorer then
explorer.view:restore_tab_state() explorer.view:restore_tab_state()
end end