File tree Expand file tree Collapse file tree 1 file changed +9
-22
lines changed Expand file tree Collapse file tree 1 file changed +9
-22
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ local notify = require("nvim-tree.notify")
55
66local find_file = require (" nvim-tree.actions.finders.find-file" ).fn
77
8+ local FileNode = require (" nvim-tree.node.file" )
89local DirectoryNode = require (" nvim-tree.node.directory" )
910
1011local M = {}
@@ -31,35 +32,21 @@ local function get_num_nodes(iter)
3132 return i
3233end
3334
34- --- @param node Node
35- --- @return string
36- local function get_containing_folder (node )
37- if node .nodes ~= nil then
38- return utils .path_add_trailing (node .absolute_path )
39- end
40- local node_name_size = # (node .name or " " )
41- return node .absolute_path :sub (0 , - node_name_size - 1 )
42- end
43-
4435--- @param node Node ?
4536function M .fn (node )
46- local cwd = core .get_cwd ()
47- if cwd == nil then
37+ node = node or core .get_explorer () --[[ @as Node ]]
38+ if not node then
4839 return
4940 end
5041
51- if not node or node .name == " .." then
52- node = {
53- absolute_path = cwd ,
54- name = " " ,
55- nodes = core .get_explorer ().nodes ,
56- open = true ,
57- }
58- elseif node :is (DirectoryNode ) then
59- node = node :last_group_node ()
42+ local dir = node :is (FileNode ) and node .parent or node :as (DirectoryNode )
43+ if not dir then
44+ return
6045 end
6146
62- local containing_folder = get_containing_folder (node )
47+ dir = dir :last_group_node ()
48+
49+ local containing_folder = utils .path_add_trailing (dir .absolute_path )
6350
6451 local input_opts = {
6552 prompt = " Create file " ,
You can’t perform that action at this time.
0 commit comments