Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,9 @@ You can easily implement a toggle using this too:
>
local function toggle_replace()
local view = require"nvim-tree.view"
local api = require"nvim-tree.api"
if view.is_visible() then
view.close()
api.close()
else
require"nvim-tree".open_replacing_current_buffer()
end
Expand Down
9 changes: 6 additions & 3 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ M.on_keypress = require("nvim-tree.actions.dispatch").dispatch

function M.toggle(find_file, no_focus, cwd, bang)
if view.is_visible() then
view.close()
view.close() -- TODO Choose one
-- view.close_this_tab_only() -- TODO Choose one
else
local previous_buf = vim.api.nvim_get_current_buf()
M.open(cwd)
Expand Down Expand Up @@ -438,7 +439,8 @@ local function setup_autocommands(opts)
pattern = "NvimTree_*",
callback = function()
if utils.is_nvim_tree_buf(0) then
view.close()
view.close() -- TODO Choose one
-- view.close_this_tab_only() -- TODO Choose one
end
end,
})
Expand Down Expand Up @@ -773,7 +775,8 @@ function M.setup(conf)
end

if M.setup_called and view.is_visible() then
view.close()
view.close() -- TODO Choose one
-- view.close_this_tab_only() -- TODO Choose one
view.abandon_current_window()
end

Expand Down
3 changes: 2 additions & 1 deletion lua/nvim-tree/actions/dispatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ local lib = require "nvim-tree.lib"
local M = {}

local Actions = {
close = view.close,
-- close = view.close(), -- TODO Choose one
close = view.close_this_tab_only(), -- TODO Choose one

-- Tree modifiers
collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn,
Expand Down
6 changes: 4 additions & 2 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ end

local function open_file_in_tab(filename)
if M.quit_on_open then
view.close()
view.close() -- TODO Choose one
-- view.close_this_tab_only() -- TODO Choose one
end
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
end
Expand Down Expand Up @@ -306,7 +307,8 @@ function M.fn(mode, filename)
end

if M.quit_on_open then
view.close()
view.close() -- TODO Choose one
-- view.close_this_tab_only() -- TODO Choose one
end
end

Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ end
Api.tree.open = require("nvim-tree").open
Api.tree.toggle = require("nvim-tree").toggle
Api.tree.close = require("nvim-tree.view").close
Api.tree.close_this_tab = require("nvim-tree.view").close_this_tab_only
Api.tree.focus = require("nvim-tree").focus
Api.tree.reload = require("nvim-tree.actions.reloaders.reloaders").reload_explorer
Api.tree.change_root = require("nvim-tree").change_dir
Expand Down
3 changes: 2 additions & 1 deletion lua/nvim-tree/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ function M.open(cwd)
core.init(cwd or vim.loop.cwd())
end
if should_hijack_current_buf() then
view.close()
-- view.close() -- TODO Choose one
view.close_this_tab_only() -- TODO Choose one
view.open_in_current_win()
renderer.draw()
else
Expand Down
3 changes: 2 additions & 1 deletion lua/nvim-tree/live-filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ local function remove_overlay()
group = vim.api.nvim_create_augroup("NvimTree", { clear = false }),
callback = function()
if utils.is_nvim_tree_buf(0) then
view.close()
view.close() -- TODO Choose one
-- view.close_this_tab_only() -- TODO Choose one
end
end,
})
Expand Down
18 changes: 17 additions & 1 deletion lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ local function save_tab_state()
M.View.cursors[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr())
end

function M.close()
local function close(all_tabpages)
if not M.is_visible() then
return
end
Expand All @@ -201,12 +201,27 @@ function M.close()
if vim.api.nvim_win_is_valid(tree_win) then
vim.api.nvim_win_close(tree_win, true)
end
if all_tabpages then
for _, v in pairs(M.View.tabpages) do
if v.winnr and vim.api.nvim_win_is_valid(v.winnr) then
vim.api.nvim_win_close(v.winnr, true)
end
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing when the tree is not open in the current tab:

    tab = {
      sync = {
        open = false,
        close = false,
        ignore = {},
      },
    },

Fail:

:NvimTreeOpen
:tabnew
:lua require"nvim-tree.api".tree.close_in_all_tabs()

Pass:

:NvimTreeOpen
:tabnew
:NvimTreeOpen
:lua require"nvim-tree.api".tree.close_in_all_tabs()

It looks like we will need to move the all-tabs-closing bit out of the nvim_list_wins loop.

events._dispatch_on_tree_close()
return
end
end
end

function M.close_this_tab_only()
close(false)
end

function M.close()
close(M.View.open_on_tab)
end

function M.open(options)
if M.is_visible() then
return
Expand Down Expand Up @@ -450,6 +465,7 @@ function M.setup(opts)
M.View.height = options.height
M.View.initial_width = get_size()
M.View.hide_root_folder = options.hide_root_folder
M.View.open_on_tab = opts.open_on_tab
M.View.preserve_window_proportions = options.preserve_window_proportions
M.View.winopts.number = options.number
M.View.winopts.relativenumber = options.relativenumber
Expand Down