Skip to content

Commit 28281aa

Browse files
committed
Merge branch 'master' into 3088-gen_vimdoc-api-3231-remove-api-requires
2 parents a79a495 + 1701e41 commit 28281aa

File tree

11 files changed

+161
-159
lines changed

11 files changed

+161
-159
lines changed

lua/nvim-tree.lua

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

15+
--- Helper function to execute some explorer method safely
16+
---@param fn string # key of explorer
17+
---@param ... any|nil
18+
---@return function|nil
19+
local function explorer_fn(fn, ...)
20+
local explorer = core.get_explorer()
21+
if explorer then
22+
return explorer[fn](explorer, ...)
23+
end
24+
end
25+
1526
--- Update the tree root to a directory or the directory containing
1627
---@param path string relative or absolute
1728
---@param bufnr number|nil
@@ -48,7 +59,7 @@ function M.change_root(path, bufnr)
4859
-- test if in vim_cwd
4960
if utils.path_relative(path, vim_cwd) ~= path then
5061
if vim_cwd ~= cwd then
51-
actions.root.change_dir.fn(vim_cwd)
62+
explorer_fn("change_dir", vim_cwd)
5263
end
5364
return
5465
end
@@ -59,19 +70,19 @@ function M.change_root(path, bufnr)
5970

6071
-- otherwise test M.init_root
6172
if _config.prefer_startup_root and utils.path_relative(path, M.init_root) ~= path then
62-
actions.root.change_dir.fn(M.init_root)
73+
explorer_fn("change_dir", M.init_root)
6374
return
6475
end
6576
-- otherwise root_dirs
6677
for _, dir in pairs(_config.root_dirs) do
6778
dir = vim.fn.fnamemodify(dir, ":p")
6879
if utils.path_relative(path, dir) ~= path then
69-
actions.root.change_dir.fn(dir)
80+
explorer_fn("change_dir", dir)
7081
return
7182
end
7283
end
7384
-- finally fall back to the folder containing the file
74-
actions.root.change_dir.fn(vim.fn.fnamemodify(path, ":p:h"))
85+
explorer_fn("change_dir", vim.fn.fnamemodify(path, ":p:h"))
7586
end
7687

7788
function M.tab_enter()
@@ -111,7 +122,13 @@ function M.open_on_directory()
111122
return
112123
end
113124

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

117134
---@return table
@@ -135,7 +152,7 @@ end
135152
---@param name string|nil
136153
function M.change_dir(name)
137154
if name then
138-
actions.root.change_dir.fn(name)
155+
explorer_fn("change_dir", name)
139156
end
140157

141158
if _config.update_focused_file.update_root.enable then

lua/nvim-tree/actions/finders/find-file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function M.fn(path)
6666
dir.open = true
6767
end
6868
if #dir.nodes == 0 then
69-
core.get_explorer():expand(dir)
69+
core.get_explorer():expand_dir_node(dir)
7070
if dir.group_next and incremented_line then
7171
line = line - 1
7272
end

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/actions/tree/modifiers/expand.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ local function expand(node)
2323
node = node:last_group_node()
2424
node.open = true
2525
if #node.nodes == 0 then
26-
core.get_explorer():expand(node)
26+
core.get_explorer():expand_dir_node(node)
2727
end
2828
end
2929

@@ -66,7 +66,7 @@ local function should_expand(expansion_count, node, should_descend)
6666

6767
if not dir.open and should_descend(expansion_count, node) then
6868
if #node.nodes == 0 then
69-
core.get_explorer():expand(dir) -- populate node.group_next
69+
core.get_explorer():expand_dir_node(dir) -- populate node.group_next
7070
end
7171

7272
if dir.group_next then

lua/nvim-tree/api/impl/post.lua

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ local view = require("nvim-tree.view")
22
local actions = require("nvim-tree.actions")
33

44
local DirectoryNode = require("nvim-tree.node.directory")
5-
local FileNode = require("nvim-tree.node.file")
65
local FileLinkNode = require("nvim-tree.node.file-link")
76
local RootNode = require("nvim-tree.node.root")
87

@@ -139,23 +138,7 @@ local function hydrate_post(api)
139138

140139
api.tree.change_root = require("nvim-tree").change_dir
141140

142-
api.tree.change_root_to_node = wrap_node(function(node)
143-
if node.name == ".." or node:is(RootNode) then
144-
actions.root.change_dir.fn("..")
145-
return
146-
end
147-
148-
if node:is(FileNode) and node.parent ~= nil then
149-
actions.root.change_dir.fn(node.parent:last_group_node().absolute_path)
150-
return
151-
end
152-
153-
if node:is(DirectoryNode) then
154-
actions.root.change_dir.fn(node:last_group_node().absolute_path)
155-
return
156-
end
157-
end)
158-
141+
api.tree.change_root_to_node = wrap_node(wrap_explorer("change_dir_to_node"))
159142
api.tree.change_root_to_parent = wrap_node(wrap_explorer("dir_up"))
160143
api.tree.get_node_under_cursor = wrap_explorer("get_node_at_cursor")
161144
api.tree.get_nodes = wrap_explorer("get_nodes")

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)