Skip to content

Commit feabc26

Browse files
committed
refactor(#3255): wire node.navigate.parent API impl directly to functions
1 parent 491350b commit feabc26

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

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

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,45 @@ local DirectoryNode = require("nvim-tree.node.directory")
33

44
local M = {}
55

6-
---@param should_close boolean|nil
7-
---@return fun(node: Node): boolean|nil
8-
function M.fn(should_close)
9-
should_close = should_close or false
10-
11-
---@param node Node
12-
return function(node)
13-
local dir = node:as(DirectoryNode)
14-
if dir then
15-
dir = dir:last_group_node()
16-
if should_close and dir.open then
17-
dir.open = false
18-
dir.explorer.renderer:draw()
19-
return
20-
end
6+
---@param node Node
7+
---@param should_close boolean
8+
local function move(node, should_close)
9+
local dir = node:as(DirectoryNode)
10+
if dir then
11+
dir = dir:last_group_node()
12+
if should_close and dir.open then
13+
dir.open = false
14+
dir.explorer.renderer:draw()
15+
return
2116
end
17+
end
2218

23-
local parent = (node:get_parent_of_group() or node).parent
19+
local parent = (node:get_parent_of_group() or node).parent
2420

25-
if not parent or not parent.parent then
26-
view.set_cursor({ 1, 0 })
27-
return
28-
end
21+
if not parent or not parent.parent then
22+
view.set_cursor({ 1, 0 })
23+
return
24+
end
2925

30-
local _, line = parent.explorer:find_node(function(n)
31-
return n.absolute_path == parent.absolute_path
32-
end)
26+
local _, line = parent.explorer:find_node(function(n)
27+
return n.absolute_path == parent.absolute_path
28+
end)
3329

34-
view.set_cursor({ line + 1, 0 })
35-
if should_close then
36-
parent.open = false
37-
parent.explorer.renderer:draw()
38-
end
30+
view.set_cursor({ line + 1, 0 })
31+
if should_close then
32+
parent.open = false
33+
parent.explorer.renderer:draw()
3934
end
4035
end
4136

37+
---@param node Node
38+
function M.move(node)
39+
move(node, false)
40+
end
41+
42+
---@param node Node
43+
function M.move_close(node)
44+
move(node, true)
45+
end
46+
4247
return M

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ function M.hydrate(api)
211211
api.node.navigate.sibling.prev = wrap_node(actions.moves.sibling.prev)
212212
api.node.navigate.sibling.first = wrap_node(actions.moves.sibling.first)
213213
api.node.navigate.sibling.last = wrap_node(actions.moves.sibling.last)
214-
api.node.navigate.parent = wrap_node(actions.moves.parent.fn(false))
215-
api.node.navigate.parent_close = wrap_node(actions.moves.parent.fn(true))
214+
api.node.navigate.parent = wrap_node(actions.moves.parent.move)
215+
api.node.navigate.parent_close = wrap_node(actions.moves.parent.move_close)
216216
api.node.navigate.git.next = wrap_node(actions.moves.item.fn({ where = "next", what = "git" }))
217217
api.node.navigate.git.next_skip_gitignored = wrap_node(actions.moves.item.fn({ where = "next", what = "git", skip_gitignored = true }))
218218
api.node.navigate.git.next_recursive = wrap_node(actions.moves.item.fn({ where = "next", what = "git", recurse = true }))

0 commit comments

Comments
 (0)