-
-
Notifications
You must be signed in to change notification settings - Fork 619
/
Copy pathparent.lua
44 lines (36 loc) · 1.05 KB
/
parent.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local renderer = require "nvim-tree.renderer"
local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local lib = require "nvim-tree.lib"
local M = {}
---@param should_close boolean|nil
---@return fun(node: Node): boolean|nil
function M.fn(should_close)
should_close = should_close or false
return function(node)
node = lib.get_last_group_node(node)
if should_close and node.open then
node.open = false
return renderer.draw()
end
local parent = utils.get_parent_of_group(node).parent
if not parent or not parent.parent then
local explorer = core.get_explorer()
if explorer then
return explorer.view:set_cursor { 1, 0 }
end
end
local _, line = utils.find_node(core.get_explorer().nodes, function(n)
return n.absolute_path == parent.absolute_path
end)
local explorer = core.get_explorer()
if explorer then
explorer.view:set_cursor { line + 1, 0 }
end
if should_close then
parent.open = false
renderer.draw()
end
end
end
return M