Skip to content

Commit 73ab312

Browse files
committed
refactor: simplify opening file in new tab
fixes #1271. Also fixes opening a file in new tab when close_on_open was true. This introduces breaking change since we don't do any extra behavior and let the buffer be opened by the tree. The previous behavior was a bit old and i believe this should've been fixed by now. Reference this commit if unexpected behavior appears while opening files in new tabs from nvim-tree.
1 parent 9d6f4c1 commit 73ab312

File tree

2 files changed

+1
-27
lines changed

2 files changed

+1
-27
lines changed

lua/nvim-tree/actions/open-file.lua

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,33 +131,7 @@ end
131131
local function open_file_in_tab(filename)
132132
if M.quit_on_open then
133133
view.close()
134-
else
135-
-- Switch window first to ensure new window doesn't inherit settings from
136-
-- NvimTree
137-
if lib.target_winid > 0 and api.nvim_win_is_valid(lib.target_winid) then
138-
api.nvim_set_current_win(lib.target_winid)
139-
else
140-
vim.cmd "wincmd p"
141-
end
142-
end
143-
144-
-- This sequence of commands are here to ensure a number of things: the new
145-
-- buffer must be opened in the current tabpage first so that focus can be
146-
-- brought back to the tree if it wasn't quit_on_open. It also ensures that
147-
-- when we open the new tabpage with the file, its window doesn't inherit
148-
-- settings from NvimTree, as it was already loaded.
149-
150-
vim.cmd("edit " .. vim.fn.fnameescape(filename))
151-
152-
local alt_bufid = vim.fn.bufnr "#"
153-
if alt_bufid ~= -1 then
154-
api.nvim_set_current_buf(alt_bufid)
155134
end
156-
157-
if not M.quit_on_open then
158-
vim.cmd "wincmd p"
159-
end
160-
161135
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
162136
end
163137

lua/nvim-tree/view.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ end
254254
function M.is_visible(opts)
255255
if opts and opts.any_tabpage then
256256
for _, v in pairs(M.View.tabpages) do
257-
if a.nvim_win_is_valid(v.winnr) then
257+
if v.winnr and a.nvim_win_is_valid(v.winnr) then
258258
return true
259259
end
260260
end

0 commit comments

Comments
 (0)