Skip to content

Commit e98b125

Browse files
committed
Pass state to get_folder_node (instead of tree)
1 parent 11870a6 commit e98b125

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ local Preview = require("neo-tree.sources.common.preview")
1515
---@param tree table to look for nodes
1616
---@param node table to look for folder parent
1717
---@return table table
18-
local function get_folder_node(tree, node)
18+
local function get_folder_node(state, node)
19+
local tree = state.tree
1920
if not node then
2021
node = tree:get_node()
2122
end
@@ -27,7 +28,7 @@ local function get_folder_node(tree, node)
2728
if node.type == "directory" then
2829
return node
2930
end
30-
return get_folder_node(tree, tree:get_node(node:get_parent_id()))
31+
return get_folder_node(state, tree:get_node(node:get_parent_id()))
3132
end
3233

3334
---The using_root_directory is used to decide what part of the filename to show
@@ -36,7 +37,7 @@ end
3637
---@return string The root path from which the relative source path should be taken
3738
local function get_using_root_directory(state)
3839
-- default to showing only the basename of the path
39-
local using_root_directory = get_folder_node(state.tree):get_id()
40+
local using_root_directory = get_folder_node(state):get_id()
4041
local show_path = state.config.show_path
4142
if show_path == "absolute" then
4243
using_root_directory = ""
@@ -70,8 +71,7 @@ end
7071
---@param state table The state of the source
7172
---@param callback function The callback to call when the command is done. Called with the parent node as the argument.
7273
M.add = function(state, callback)
73-
local tree = state.tree
74-
local node = get_folder_node(tree)
74+
local node = get_folder_node(state)
7575
local in_directory = node:get_id()
7676
local using_root_directory = get_using_root_directory(state)
7777
fs_actions.create_node(in_directory, callback, using_root_directory)
@@ -81,8 +81,7 @@ end
8181
---@param state table The state of the source
8282
---@param callback function The callback to call when the command is done. Called with the parent node as the argument.
8383
M.add_directory = function(state, callback)
84-
local tree = state.tree
85-
local node = get_folder_node(tree)
84+
local node = get_folder_node(state)
8685
local in_directory = node:get_id()
8786
local using_root_directory = get_using_root_directory(state)
8887
fs_actions.create_directory(in_directory, callback, using_root_directory)
@@ -361,7 +360,7 @@ end
361360
---@param callback function The callback to call when the command is done. Called with the parent node as the argument.
362361
M.paste_from_clipboard = function(state, callback)
363362
if state.clipboard then
364-
local folder = get_folder_node(state.tree):get_id()
363+
local folder = get_folder_node(state):get_id()
365364
-- Convert to list so to make it easier to pop items from the stack.
366365
local clipboard_list = {}
367366
for _, item in pairs(state.clipboard) do

0 commit comments

Comments
 (0)