Skip to content

Commit f04d156

Browse files
committed
fix(files): fix nil reference errors related to spit browsing
1 parent 1c20a2e commit f04d156

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

lua/neo-tree/sources/common/commands.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ end
156156
---open/closed
157157
local open_with_cmd = function(state, open_cmd, toggle_directory)
158158
local tree = state.tree
159-
local node = tree:get_node()
160-
if not node then
159+
local success, node = pcall(tree.get_node, tree)
160+
if not success and node then
161+
log.error("Could not get node.")
161162
return
162163
end
163164
if node.type == "directory" then

lua/neo-tree/sources/filesystem/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ M.reset_search = function(state, refresh, open_current_node)
173173
state.open_folders_before_search = nil
174174
if refresh then
175175
if open_current_node then
176-
local node = state.tree:get_node()
177-
if node then
176+
local success, node = pcall(state.tree.get_node, state.tree)
177+
if success and node then
178178
local path = node:get_id()
179179
state.position.set(path)
180180
if node.type == "directory" then

lua/neo-tree/sources/manager.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,15 @@ M.reveal_in_split = function(source_name, callback)
413413
local state = M.get_state(source_name, nil, vim.api.nvim_get_current_win())
414414
state.current_position = "split"
415415
local path_to_reveal = M.get_path_to_reveal()
416+
if not path_to_reveal then
417+
M.navigate(state, nil, nil, callback)
418+
return
419+
end
416420
local cwd = state.path
417421
if cwd == nil then
418422
cwd = M.get_cwd(state)
419423
end
420-
if not utils.is_subpath(cwd, path_to_reveal) then
424+
if cwd and not utils.is_subpath(cwd, path_to_reveal) then
421425
state.path = utils.split_path(path_to_reveal)[1]
422426
end
423427
M.navigate(state, state.path, path_to_reveal, callback)

0 commit comments

Comments
 (0)