Skip to content

Commit 6604275

Browse files
authored
feat: allow set_root command from any node (#1420)
1 parent 54b622d commit 6604275

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

Diff for: lua/neo-tree/sources/buffers/commands.lua

+10-4
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ M.rename = function(state)
8080
end
8181

8282
M.set_root = function(state)
83-
local tree = state.tree
84-
local node = tree:get_node()
85-
if node.type == "directory" then
86-
buffers.navigate(state, node.id)
83+
local node = state.tree:get_node()
84+
while node and node.type ~= "directory" do
85+
local parent_id = node:get_parent_id()
86+
node = parent_id and state.tree:get_node(parent_id) or nil
87+
end
88+
89+
if not node then
90+
return
8791
end
92+
93+
buffers.navigate(state, node:get_id())
8894
end
8995

9096
cc._add_common_commands(M)

Diff for: lua/neo-tree/sources/filesystem/commands.lua

+14-7
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,21 @@ M.rename = function(state)
222222
end
223223

224224
M.set_root = function(state)
225-
local tree = state.tree
226-
local node = tree:get_node()
227-
if node.type == "directory" then
228-
if state.search_pattern then
229-
fs.reset_search(state, false)
230-
end
231-
fs._navigate_internal(state, node.id, nil, nil, false)
225+
if state.search_pattern then
226+
fs.reset_search(state, false)
227+
end
228+
229+
local node = state.tree:get_node()
230+
while node and node.type ~= "directory" do
231+
local parent_id = node:get_parent_id()
232+
node = parent_id and state.tree:get_node(parent_id) or nil
232233
end
234+
235+
if not node then
236+
return
237+
end
238+
239+
fs._navigate_internal(state, node:get_id(), nil, nil, false)
233240
end
234241

235242
---Toggles whether hidden files are shown or not.

0 commit comments

Comments
 (0)