Skip to content

Commit f7bd731

Browse files
committed
feat(#2826): add feature gate experimental.close_other_windows_in_tab
1 parent f322a20 commit f7bd731

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

lua/nvim-tree/explorer/view.lua

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ end
107107
---@private
108108
---@param bufnr integer
109109
function View:create_autocmds(bufnr)
110-
-- clear bufnr and winid
111110
-- eject buffer opened in the nvim-tree window and create a new buffer
112111
vim.api.nvim_create_autocmd("BufWipeout", {
113112
group = self.explorer.augroup_id,
@@ -128,7 +127,6 @@ function View:create_autocmds(bufnr)
128127
end,
129128
})
130129

131-
-- close any other windows containing this buffer
132130
-- not fired when entering the first window, only subsequent event such as following a split
133131
-- does fire on :tabnew for _any_ buffer
134132
vim.api.nvim_create_autocmd("WinEnter", {
@@ -149,27 +147,39 @@ function View:create_autocmds(bufnr)
149147
return
150148
end
151149

152-
-- are there any other windows containing bufnr?
153-
local winids_buf = vim.fn.win_findbuf(bufnr)
154-
if #winids_buf <= 1 then
155-
return
156-
end
157-
158-
-- close all other windows
159-
local winid_cur = vim.api.nvim_get_current_win()
160-
for _, winid in ipairs(winids_buf) do
161-
if winid ~= winid_cur then
162-
pcall(vim.api.nvim_win_close, winid, false)
163-
end
164-
end
165-
166-
-- setup this window, it may be new e.g. split
167-
self:set_window_options_and_buffer()
168-
self:resize()
150+
-- close other windows in this tab
151+
self:close_other_windows(bufnr)
169152
end,
170153
})
171154
end
172155

156+
---Close any other windows containing this buffer and setup current window
157+
---Feature gated behind experimental.close_other_windows_in_tab
158+
---@param bufnr integer
159+
function View:close_other_windows(bufnr)
160+
if not self.explorer.opts.experimental.close_other_windows_in_tab then
161+
return
162+
end
163+
164+
-- are there any other windows containing bufnr?
165+
local winids_buf = vim.fn.win_findbuf(bufnr)
166+
if #winids_buf <= 1 then
167+
return
168+
end
169+
170+
-- close all other windows
171+
local winid_cur = vim.api.nvim_get_current_win()
172+
for _, winid in ipairs(winids_buf) do
173+
if winid ~= winid_cur then
174+
pcall(vim.api.nvim_win_close, winid, false)
175+
end
176+
end
177+
178+
-- setup current window, it may be new e.g. split
179+
self:set_window_options_and_buffer()
180+
self:resize()
181+
end
182+
173183
-- TODO multi-instance remove this; delete buffers rather than retaining them
174184
---@private
175185
---@param bufnr integer

0 commit comments

Comments
 (0)