Skip to content

fix: remove redundant file existence check in create file operation #1936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions lua/nvim-tree/actions/fs/create-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ local function create_and_notify(file)
events._dispatch_file_created(file)
end

local function create_file(file)
if utils.file_exists(file) then
local prompt_select = "Overwrite " .. file .. " ?"
local prompt_input = prompt_select .. " y/n: "
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
utils.clear_prompt()
if item_short == "y" then
create_and_notify(file)
end
end)
else
create_and_notify(file)
end
end

local function get_num_nodes(iter)
local i = 0
for _ in iter do
Expand Down Expand Up @@ -91,7 +76,7 @@ function M.fn(node)
path_to_create = utils.path_join { path_to_create, p }
end
if is_last_path_file and idx == num_nodes then
create_file(path_to_create)
create_and_notify(path_to_create)
elseif not utils.file_exists(path_to_create) then
local success = vim.loop.fs_mkdir(path_to_create, 493)
if not success then
Expand Down