From 73ab31282000dd5ccf52def8869e5f8e89388138 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sat, 21 May 2022 12:09:09 +0200 Subject: [PATCH] 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. --- lua/nvim-tree/actions/open-file.lua | 26 -------------------------- lua/nvim-tree/view.lua | 2 +- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/lua/nvim-tree/actions/open-file.lua b/lua/nvim-tree/actions/open-file.lua index 9079120c..b2f7315c 100644 --- a/lua/nvim-tree/actions/open-file.lua +++ b/lua/nvim-tree/actions/open-file.lua @@ -131,33 +131,7 @@ end local function open_file_in_tab(filename) if M.quit_on_open then view.close() - else - -- Switch window first to ensure new window doesn't inherit settings from - -- NvimTree - if lib.target_winid > 0 and api.nvim_win_is_valid(lib.target_winid) then - api.nvim_set_current_win(lib.target_winid) - else - vim.cmd "wincmd p" - end end - - -- This sequence of commands are here to ensure a number of things: the new - -- buffer must be opened in the current tabpage first so that focus can be - -- brought back to the tree if it wasn't quit_on_open. It also ensures that - -- when we open the new tabpage with the file, its window doesn't inherit - -- settings from NvimTree, as it was already loaded. - - vim.cmd("edit " .. vim.fn.fnameescape(filename)) - - local alt_bufid = vim.fn.bufnr "#" - if alt_bufid ~= -1 then - api.nvim_set_current_buf(alt_bufid) - end - - if not M.quit_on_open then - vim.cmd "wincmd p" - end - vim.cmd("tabe " .. vim.fn.fnameescape(filename)) end diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index adb00c24..be972adf 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -254,7 +254,7 @@ end function M.is_visible(opts) if opts and opts.any_tabpage then for _, v in pairs(M.View.tabpages) do - if a.nvim_win_is_valid(v.winnr) then + if v.winnr and a.nvim_win_is_valid(v.winnr) then return true end end