Skip to content

Commit 09ec00c

Browse files
committed
refactor(#2826): get_winid returns new after consistency check
1 parent 3615c7d commit 09ec00c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lua/nvim-tree/explorer/view.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ end
539539
---@param opts table|nil
540540
---@return boolean
541541
function View:is_visible(opts)
542+
-- TODO multi-instance rewrite and consistency check
542543
if opts and opts.tabpage then
543544
if globals.TABPAGES[opts.tabpage] == nil then
544545
return false
@@ -618,10 +619,10 @@ function View:winid(tabpage, callsite)
618619
local msg = string.format("View:winid(%3s, %-20.20s)", tabpage, callsite)
619620

620621
if bufnr then
621-
for _, w in pairs(vim.api.nvim_tabpage_list_wins(tabpage or 0)) do
622-
if vim.api.nvim_win_get_buf(w) == bufnr then
623-
log.line("dev", "%s b%d : w%s", msg, bufnr, w)
624-
return w
622+
for _, winid in pairs(vim.api.nvim_tabpage_list_wins(tabpage or 0)) do
623+
if vim.api.nvim_win_get_buf(winid) == bufnr then
624+
log.line("dev", "%s b%d : w%s", msg, bufnr, winid)
625+
return winid
625626
end
626627
end
627628
else
@@ -669,6 +670,8 @@ function View:get_winid(tabpage, callsite)
669670
if winid ~= tabinfo_winid then
670671
notify.error(msg)
671672
end
673+
674+
return winid
672675
end
673676

674677
-- legacy codepath
@@ -712,6 +715,7 @@ function View:prevent_buffer_override()
712715
local curbuf = vim.api.nvim_win_get_buf(curwin)
713716
local bufname = vim.api.nvim_buf_get_name(curbuf)
714717

718+
--- TODO multi-instance this can be removed as winid() will handle it
715719
if not bufname:match("NvimTree") then
716720
for i, tabpage in ipairs(globals.TABPAGES) do
717721
if tabpage.winid == view_winid then

lua/nvim-tree/lib.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function M.open(opts)
135135
open_view_and_draw()
136136
end
137137

138+
-- TODO multi-instance is this actually necessary?
138139
if explorer then
139140
explorer.view:restore_tab_state()
140141
end

0 commit comments

Comments
 (0)