Skip to content

Commit 735381a

Browse files
committed
simplify parent
1 parent 5e5cdaa commit 735381a

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

lua/nvim-tree/actions/moves/parent.lua

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local view = require("nvim-tree.view")
22
local utils = require("nvim-tree.utils")
3-
local core = require("nvim-tree.core")
43

54
local DirectoryNode = require("nvim-tree.node.directory")
65

@@ -11,17 +10,16 @@ local M = {}
1110
function M.fn(should_close)
1211
should_close = should_close or false
1312

13+
---@param node Node
1414
return function(node)
15-
local explorer = core.get_explorer()
16-
if node:is(DirectoryNode) then
17-
node = node:last_group_node()
18-
end
19-
if should_close and node.open then
20-
node.open = false
21-
if explorer then
22-
explorer.renderer:draw()
15+
local dir = node:as(DirectoryNode)
16+
if dir then
17+
dir = dir:last_group_node()
18+
if should_close and dir.open then
19+
dir.open = false
20+
dir.explorer.renderer:draw()
21+
return
2322
end
24-
return
2523
end
2624

2725
local parent = (node:get_parent_of_group() or node).parent
@@ -30,16 +28,14 @@ function M.fn(should_close)
3028
return view.set_cursor({ 1, 0 })
3129
end
3230

33-
local _, line = utils.find_node(core.get_explorer().nodes, function(n)
31+
local _, line = utils.find_node(parent.explorer.nodes, function(n)
3432
return n.absolute_path == parent.absolute_path
3533
end)
3634

3735
view.set_cursor({ line + 1, 0 })
3836
if should_close then
3937
parent.open = false
40-
if explorer then
41-
explorer.renderer:draw()
42-
end
38+
parent.explorer.renderer:draw()
4339
end
4440
end
4541
end

0 commit comments

Comments
 (0)