Skip to content

Commit

Permalink
revert changes to create-file, handle in #2924
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Sep 23, 2024
1 parent 0ed0b81 commit f998996
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lua/nvim-tree/actions/fs/create-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ local function get_num_nodes(iter)
return i
end

---@param has_children boolean
---@param absolute_path string
---@param name string
---@param node Node
---@return string
local function get_containing_folder(has_children, absolute_path, name)
if has_children then
return utils.path_add_trailing(absolute_path)
local function get_containing_folder(node)
if node.nodes ~= nil then
return utils.path_add_trailing(node.absolute_path)
end
local node_name_size = #(name or "")
return absolute_path:sub(0, -node_name_size - 1)
local node_name_size = #(node.name or "")
return node.absolute_path:sub(0, -node_name_size - 1)
end

---@param node Node|nil
Expand All @@ -48,15 +46,19 @@ function M.fn(node)
return
end

node = node and node:last_group_node()

local containing_folder
if not node or node.name == ".." then
containing_folder = get_containing_folder(core.get_explorer().nodes ~= nil, cwd, "")
node = {
absolute_path = cwd,
name = "",
nodes = core.get_explorer().nodes,
open = true,
}
else
containing_folder = get_containing_folder(node.nodes ~= nil, node.absolute_path, node.name)
node = node:last_group_node()
end

local containing_folder = get_containing_folder(node)

local input_opts = {
prompt = "Create file ",
default = containing_folder,
Expand Down

0 comments on commit f998996

Please sign in to comment.