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