feat(create-file): use vim.ui.select for confirmation

fixes #1434
fixes #1294
This commit is contained in:
kiyan
2022-07-18 14:32:19 +02:00
parent 2d629cab78
commit 1ee6a3ea65
3 changed files with 25 additions and 25 deletions

View File

@@ -7,15 +7,7 @@ local core = require "nvim-tree.core"
local M = {}
local function create_file(file)
if utils.file_exists(file) then
print(file .. " already exists. Overwrite? y/n")
local ans = utils.get_user_input_char()
utils.clear_prompt()
if ans ~= "y" then
return
end
end
local function create_and_notify(file)
local ok, fd = pcall(uv.fs_open, file, "w", 420)
if not ok then
utils.notify.error("Couldn't create file " .. file)
@@ -25,6 +17,18 @@ local function create_file(file)
events._dispatch_file_created(file)
end
local function create_file(file)
if utils.file_exists(file) then
vim.ui.select({ "y", "n" }, { prompt = file .. " already exists. Overwrite?" }, function(choice)
if choice == "y" then
create_and_notify()
end
end)
else
create_and_notify()
end
end
local function get_num_nodes(iter)
local i = 0
for _ in iter do
@@ -61,8 +65,6 @@ function M.fn(node)
return
end
utils.clear_prompt()
if utils.file_exists(new_file_path) then
utils.notify.warn "Cannot create: file already exists"
return