Skip to content

Commit eb52ca7

Browse files
committed
merge with master
2 parents 7822481 + 1701e41 commit eb52ca7

File tree

8 files changed

+157
-155
lines changed

8 files changed

+157
-155
lines changed

lua/nvim-tree.lua

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ local M = {
1111
init_root = "",
1212
}
1313

14+
--- Helper function to execute some explorer method safely
15+
---@param fn string # key of explorer
16+
---@param ... any|nil
17+
---@return function|nil
18+
local function explorer_fn(fn, ...)
19+
local explorer = core.get_explorer()
20+
if explorer then
21+
return explorer[fn](explorer, ...)
22+
end
23+
end
24+
1425
--- Update the tree root to a directory or the directory containing
1526
---@param path string relative or absolute
1627
---@param bufnr number|nil
@@ -47,7 +58,7 @@ function M.change_root(path, bufnr)
4758
-- test if in vim_cwd
4859
if utils.path_relative(path, vim_cwd) ~= path then
4960
if vim_cwd ~= cwd then
50-
actions.root.change_dir.fn(vim_cwd)
61+
explorer_fn("change_dir", vim_cwd)
5162
end
5263
return
5364
end
@@ -58,19 +69,19 @@ function M.change_root(path, bufnr)
5869

5970
-- otherwise test M.init_root
6071
if _config.prefer_startup_root and utils.path_relative(path, M.init_root) ~= path then
61-
actions.root.change_dir.fn(M.init_root)
72+
explorer_fn("change_dir", M.init_root)
6273
return
6374
end
6475
-- otherwise root_dirs
6576
for _, dir in pairs(_config.root_dirs) do
6677
dir = vim.fn.fnamemodify(dir, ":p")
6778
if utils.path_relative(path, dir) ~= path then
68-
actions.root.change_dir.fn(dir)
79+
explorer_fn("change_dir", dir)
6980
return
7081
end
7182
end
7283
-- finally fall back to the folder containing the file
73-
actions.root.change_dir.fn(vim.fn.fnamemodify(path, ":p:h"))
84+
explorer_fn("change_dir", vim.fn.fnamemodify(path, ":p:h"))
7485
end
7586

7687
function M.tab_enter()
@@ -110,7 +121,13 @@ function M.open_on_directory()
110121
return
111122
end
112123

113-
actions.root.change_dir.force_dirchange(bufname, true)
124+
125+
local explorer = core.get_explorer()
126+
if not explorer then
127+
core.init(bufname)
128+
end
129+
130+
explorer_fn("force_dirchange", bufname, true, false)
114131
end
115132

116133
---@return table
@@ -134,7 +151,7 @@ end
134151
---@param name string|nil
135152
function M.change_dir(name)
136153
if name then
137-
actions.root.change_dir.fn(name)
154+
explorer_fn("change_dir", name)
138155
end
139156

140157
if _config.update_focused_file.update_root.enable then

lua/nvim-tree/actions/init.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ M.finders = require("nvim-tree.actions.finders")
44
M.fs = require("nvim-tree.actions.fs")
55
M.moves = require("nvim-tree.actions.moves")
66
M.node = require("nvim-tree.actions.node")
7-
M.root = require("nvim-tree.actions.root")
87
M.tree = require("nvim-tree.actions.tree")
98

109
function M.setup(opts)
1110
M.fs.setup(opts)
1211
M.node.setup(opts)
13-
M.root.setup(opts)
1412
M.tree.setup(opts)
1513
end
1614

lua/nvim-tree/actions/root/change-dir.lua

Lines changed: 0 additions & 105 deletions
This file was deleted.

lua/nvim-tree/actions/root/init.lua

Lines changed: 0 additions & 9 deletions
This file was deleted.

lua/nvim-tree/api.lua

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ local keymap = require("nvim-tree.keymap")
99
local notify = require("nvim-tree.notify")
1010

1111
local DirectoryNode = require("nvim-tree.node.directory")
12-
local FileNode = require("nvim-tree.node.file")
1312
local FileLinkNode = require("nvim-tree.node.file-link")
1413
local RootNode = require("nvim-tree.node.root")
1514
local UserDecorator = require("nvim-tree.renderer.decorator.user")
@@ -158,23 +157,7 @@ Api.tree.change_root = wrap(function(...)
158157
require("nvim-tree").change_dir(...)
159158
end)
160159

161-
Api.tree.change_root_to_node = wrap_node(function(node)
162-
if node.name == ".." or node:is(RootNode) then
163-
actions.root.change_dir.fn("..")
164-
return
165-
end
166-
167-
if node:is(FileNode) and node.parent ~= nil then
168-
actions.root.change_dir.fn(node.parent:last_group_node().absolute_path)
169-
return
170-
end
171-
172-
if node:is(DirectoryNode) then
173-
actions.root.change_dir.fn(node:last_group_node().absolute_path)
174-
return
175-
end
176-
end)
177-
160+
Api.tree.change_root_to_node = wrap_node(wrap_explorer("change_dir_to_node"))
178161
Api.tree.change_root_to_parent = wrap_node(wrap_explorer("dir_up"))
179162
Api.tree.get_node_under_cursor = wrap_explorer("get_node_at_cursor")
180163
Api.tree.get_nodes = wrap_explorer("get_nodes")
@@ -281,7 +264,7 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
281264
local dir = node:as(DirectoryNode)
282265

283266
if root or node.name == ".." then
284-
actions.root.change_dir.fn("..")
267+
wrap_explorer("change_dir")("..")
285268
elseif dir then
286269
dir:expand_or_collapse(toggle_group)
287270
elseif not toggle_group then

lua/nvim-tree/explorer/filters.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ function Filters:bookmark(path, path_type, bookmarks)
134134

135135
local mark_parent = utils.path_add_trailing(path)
136136
for mark, mark_type in pairs(bookmarks) do
137+
if type(mark_type) == "table" and mark_type.type then
138+
mark_type = mark_type.type
139+
end
137140
if path == mark then
138141
return false
139142
end

0 commit comments

Comments
 (0)