Skip to content

Commit a23b11d

Browse files
committed
Implement changes
1 parent 3d11c92 commit a23b11d

File tree

7 files changed

+29
-16
lines changed

7 files changed

+29
-16
lines changed

lua/nvim-tree.lua

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ M.on_keypress = require("nvim-tree.actions.dispatch").dispatch
7070

7171
function M.toggle(find_file, no_focus, cwd, bang)
7272
if view.is_visible() then
73-
M.close()
73+
view.close() -- TODO Choose one
74+
-- view.close_this_tab_only() -- TODO Choose one
7475
else
7576
local previous_buf = vim.api.nvim_get_current_buf()
7677
M.open(cwd)
@@ -83,11 +84,6 @@ function M.toggle(find_file, no_focus, cwd, bang)
8384
end
8485
end
8586

86-
function M.close()
87-
local config = M.get_config()
88-
view.close(config.open_on_tab)
89-
end
90-
9187
function M.open(cwd)
9288
cwd = cwd ~= "" and cwd or nil
9389
if view.is_visible() then
@@ -443,7 +439,8 @@ local function setup_autocommands(opts)
443439
pattern = "NvimTree_*",
444440
callback = function()
445441
if utils.is_nvim_tree_buf(0) then
446-
M.close()
442+
view.close() -- TODO Choose one
443+
-- view.close_this_tab_only() -- TODO Choose one
447444
end
448445
end,
449446
})
@@ -774,11 +771,12 @@ function M.setup(conf)
774771
require("nvim-tree.watcher").purge_watchers()
775772

776773
if not M.setup_called then
777-
setup_vim_commands(opts)
774+
setup_vim_commands()
778775
end
779776

780777
if M.setup_called and view.is_visible() then
781-
M.close()
778+
view.close() -- TODO Choose one
779+
-- view.close_this_tab_only() -- TODO Choose one
782780
view.abandon_current_window()
783781
end
784782

lua/nvim-tree/actions/dispatch.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ local lib = require "nvim-tree.lib"
44
local M = {}
55

66
local Actions = {
7-
close = view.close,
7+
-- close = view.close(), -- TODO Choose one
8+
close = view.close_this_tab_only(), -- TODO Choose one
89

910
-- Tree modifiers
1011
collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ end
143143

144144
local function open_file_in_tab(filename)
145145
if M.quit_on_open then
146-
view.close(false)
146+
view.close() -- TODO Choose one
147+
-- view.close_this_tab_only() -- TODO Choose one
147148
end
148149
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
149150
end
@@ -306,7 +307,8 @@ function M.fn(mode, filename)
306307
end
307308

308309
if M.quit_on_open then
309-
view.close(false)
310+
view.close() -- TODO Choose one
311+
-- view.close_this_tab_only() -- TODO Choose one
310312
end
311313
end
312314

lua/nvim-tree/api.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ end
1717

1818
Api.tree.open = require("nvim-tree").open
1919
Api.tree.toggle = require("nvim-tree").toggle
20-
Api.tree.close = require("nvim-tree").close
20+
Api.tree.close = require("nvim-tree.view").close
21+
Api.tree.close_this_tab = require("nvim-tree.view").close_this_tab_only
2122
Api.tree.focus = require("nvim-tree").focus
2223
Api.tree.reload = require("nvim-tree.actions.reloaders.reloaders").reload_explorer
2324
Api.tree.change_root = require("nvim-tree").change_dir

lua/nvim-tree/lib.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ function M.open(cwd)
117117
core.init(cwd or vim.loop.cwd())
118118
end
119119
if should_hijack_current_buf() then
120-
view.close(false)
120+
-- view.close() -- TODO Choose one
121+
view.close_this_tab_only() -- TODO Choose one
121122
view.open_in_current_win()
122123
renderer.draw()
123124
else

lua/nvim-tree/live-filter.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ local function remove_overlay()
3131
group = vim.api.nvim_create_augroup("NvimTree", { clear = false }),
3232
callback = function()
3333
if utils.is_nvim_tree_buf(0) then
34-
view.close(false)
34+
view.close() -- TODO Choose one
35+
-- view.close_this_tab_only() -- TODO Choose one
3536
end
3637
end,
3738
})

lua/nvim-tree/view.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ local function save_tab_state()
184184
M.View.cursors[tabpage] = vim.api.nvim_win_get_cursor(M.get_winnr())
185185
end
186186

187-
function M.close(all_tabpages)
187+
local function close(all_tabpages)
188188
if not M.is_visible() then
189189
return
190190
end
@@ -214,6 +214,14 @@ function M.close(all_tabpages)
214214
end
215215
end
216216

217+
function M.close_this_tab_only()
218+
close(false)
219+
end
220+
221+
function M.close()
222+
close(M.View.open_on_tab)
223+
end
224+
217225
function M.open(options)
218226
if M.is_visible() then
219227
return
@@ -457,6 +465,7 @@ function M.setup(opts)
457465
M.View.height = options.height
458466
M.View.initial_width = get_size()
459467
M.View.hide_root_folder = options.hide_root_folder
468+
M.View.open_on_tab = opts.open_on_tab
460469
M.View.preserve_window_proportions = options.preserve_window_proportions
461470
M.View.winopts.number = options.number
462471
M.View.winopts.relativenumber = options.relativenumber

0 commit comments

Comments
 (0)