refactor: use vim.ui.input for y/n selections
also add clear_prompt again. fixes #1441
This commit is contained in:
@@ -94,11 +94,13 @@ local function do_single_paste(source, dest, action_type, action_fn)
|
||||
end
|
||||
|
||||
if dest_stats then
|
||||
vim.ui.select({ "y", "n", "rename" }, { prompt = dest .. " already exists. Overwrite?" }, function(choice)
|
||||
vim.ui.input({ prompt = dest .. " already exists. Overwrite? y/n/r(ename): " }, function(choice)
|
||||
utils.clear_prompt()
|
||||
if choice == "y" then
|
||||
on_process()
|
||||
elseif choice == "rename" then
|
||||
elseif choice == "r" then
|
||||
vim.ui.input({ prompt = "New name: ", default = dest, completion = "dir" }, function(new_dest)
|
||||
utils.clear_prompt()
|
||||
if new_dest then
|
||||
do_single_paste(source, new_dest, action_type, action_fn)
|
||||
end
|
||||
|
||||
@@ -19,15 +19,12 @@ end
|
||||
|
||||
local function create_file(file)
|
||||
if utils.file_exists(file) then
|
||||
vim.ui.select(
|
||||
{ "y", "n" },
|
||||
{ kind = "confirmation", prompt = file .. " already exists. Overwrite?" },
|
||||
function(choice)
|
||||
if choice == "y" then
|
||||
create_and_notify(file)
|
||||
end
|
||||
vim.ui.input({ prompt = file .. " already exists. Overwrite? y/n: " }, function(choice)
|
||||
utils.clear_prompt()
|
||||
if choice == "y" then
|
||||
create_and_notify(file)
|
||||
end
|
||||
)
|
||||
end)
|
||||
else
|
||||
create_and_notify(file)
|
||||
end
|
||||
@@ -65,6 +62,7 @@ function M.fn(node)
|
||||
local input_opts = { prompt = "Create file ", default = containing_folder, completion = "file" }
|
||||
|
||||
vim.ui.input(input_opts, function(new_file_path)
|
||||
utils.clear_prompt()
|
||||
if not new_file_path or new_file_path == containing_folder then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -68,7 +68,8 @@ function M.fn(node)
|
||||
return
|
||||
end
|
||||
|
||||
vim.ui.select({ "y", "n" }, { kind = "confirmation", prompt = "Remove " .. node.name .. " ?" }, function(choice)
|
||||
vim.ui.input({ prompt = "Remove " .. node.name .. " ? y/n: " }, function(choice)
|
||||
utils.clear_prompt()
|
||||
if choice == "y" then
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
local success = remove_dir(node.absolute_path)
|
||||
|
||||
@@ -38,6 +38,7 @@ function M.fn(with_sub)
|
||||
local input_opts = { prompt = "Rename to ", default = abs_path, completion = "file" }
|
||||
|
||||
vim.ui.input(input_opts, function(new_file_path)
|
||||
utils.clear_prompt()
|
||||
if not new_file_path then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -93,7 +93,8 @@ function M.fn(node)
|
||||
end
|
||||
|
||||
if M.config.trash.require_confirm then
|
||||
vim.ui.select({ "y", "n" }, { kind = "confirmation", prompt = "Trash " .. node.name .. " ?" }, function(choice)
|
||||
vim.ui.input({ prompt = "Trash " .. node.name .. " ? y/n: " }, function(choice)
|
||||
utils.clear_prompt()
|
||||
if choice == "y" then
|
||||
do_trash()
|
||||
end
|
||||
|
||||
@@ -112,9 +112,7 @@ local function pick_window()
|
||||
end
|
||||
local _, resp = pcall(get_user_input_char)
|
||||
resp = (resp or ""):upper()
|
||||
if vim.opt.cmdheight._value ~= 0 then
|
||||
vim.api.nvim_command "normal! :"
|
||||
end
|
||||
utils.clear_prompt()
|
||||
|
||||
-- Restore window options
|
||||
for _, id in ipairs(selectable) do
|
||||
|
||||
@@ -12,6 +12,7 @@ function M.bulk_move()
|
||||
end
|
||||
|
||||
vim.ui.input({ prompt = "Move to: ", default = Core.get_cwd(), completion = "dir" }, function(location)
|
||||
utils.clear_prompt()
|
||||
if not location or location == "" then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -373,4 +373,10 @@ function M.get_win_buf_from_path(path)
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function M.clear_prompt()
|
||||
if vim.opt.cmdheight._value ~= 0 then
|
||||
vim.cmd "normal! :"
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user