1
1
local view = require (" nvim-tree.view" )
2
2
local utils = require (" nvim-tree.utils" )
3
- local core = require (" nvim-tree.core" )
4
3
5
4
local DirectoryNode = require (" nvim-tree.node.directory" )
6
5
@@ -11,17 +10,16 @@ local M = {}
11
10
function M .fn (should_close )
12
11
should_close = should_close or false
13
12
13
+ --- @param node Node
14
14
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
23
22
end
24
- return
25
23
end
26
24
27
25
local parent = (node :get_parent_of_group () or node ).parent
@@ -30,16 +28,14 @@ function M.fn(should_close)
30
28
return view .set_cursor ({ 1 , 0 })
31
29
end
32
30
33
- local _ , line = utils .find_node (core . get_explorer () .nodes , function (n )
31
+ local _ , line = utils .find_node (parent . explorer .nodes , function (n )
34
32
return n .absolute_path == parent .absolute_path
35
33
end )
36
34
37
35
view .set_cursor ({ line + 1 , 0 })
38
36
if should_close then
39
37
parent .open = false
40
- if explorer then
41
- explorer .renderer :draw ()
42
- end
38
+ parent .explorer .renderer :draw ()
43
39
end
44
40
end
45
41
end
0 commit comments