Skip to content

Commit 8dc2144

Browse files
committed
refactor: use vim.ui.input for y/n selections
also add clear_prompt again. fixes #1441
1 parent b754eb8 commit 8dc2144

File tree

8 files changed

+23
-15
lines changed

8 files changed

+23
-15
lines changed

lua/nvim-tree/actions/fs/copy-paste.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ local function do_single_paste(source, dest, action_type, action_fn)
9494
end
9595

9696
if dest_stats then
97-
vim.ui.select({ "y", "n", "rename" }, { prompt = dest .. " already exists. Overwrite?" }, function(choice)
97+
vim.ui.input({ prompt = dest .. " already exists. Overwrite? y/n/r(ename): " }, function(choice)
98+
utils.clear_prompt()
9899
if choice == "y" then
99100
on_process()
100-
elseif choice == "rename" then
101+
elseif choice == "r" then
101102
vim.ui.input({ prompt = "New name: ", default = dest, completion = "dir" }, function(new_dest)
103+
utils.clear_prompt()
102104
if new_dest then
103105
do_single_paste(source, new_dest, action_type, action_fn)
104106
end

lua/nvim-tree/actions/fs/create-file.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ end
1919

2020
local function create_file(file)
2121
if utils.file_exists(file) then
22-
vim.ui.select(
23-
{ "y", "n" },
24-
{ kind = "confirmation", prompt = file .. " already exists. Overwrite?" },
25-
function(choice)
26-
if choice == "y" then
27-
create_and_notify(file)
28-
end
22+
vim.ui.input({ prompt = file .. " already exists. Overwrite? y/n: " }, function(choice)
23+
utils.clear_prompt()
24+
if choice == "y" then
25+
create_and_notify(file)
2926
end
30-
)
27+
end)
3128
else
3229
create_and_notify(file)
3330
end
@@ -65,6 +62,7 @@ function M.fn(node)
6562
local input_opts = { prompt = "Create file ", default = containing_folder, completion = "file" }
6663

6764
vim.ui.input(input_opts, function(new_file_path)
65+
utils.clear_prompt()
6866
if not new_file_path or new_file_path == containing_folder then
6967
return
7068
end

lua/nvim-tree/actions/fs/remove-file.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ function M.fn(node)
6868
return
6969
end
7070

71-
vim.ui.select({ "y", "n" }, { kind = "confirmation", prompt = "Remove " .. node.name .. " ?" }, function(choice)
71+
vim.ui.input({ prompt = "Remove " .. node.name .. " ? y/n: " }, function(choice)
72+
utils.clear_prompt()
7273
if choice == "y" then
7374
if node.nodes ~= nil and not node.link_to then
7475
local success = remove_dir(node.absolute_path)

lua/nvim-tree/actions/fs/rename-file.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function M.fn(with_sub)
3838
local input_opts = { prompt = "Rename to ", default = abs_path, completion = "file" }
3939

4040
vim.ui.input(input_opts, function(new_file_path)
41+
utils.clear_prompt()
4142
if not new_file_path then
4243
return
4344
end

lua/nvim-tree/actions/fs/trash.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ function M.fn(node)
9393
end
9494

9595
if M.config.trash.require_confirm then
96-
vim.ui.select({ "y", "n" }, { kind = "confirmation", prompt = "Trash " .. node.name .. " ?" }, function(choice)
96+
vim.ui.input({ prompt = "Trash " .. node.name .. " ? y/n: " }, function(choice)
97+
utils.clear_prompt()
9798
if choice == "y" then
9899
do_trash()
99100
end

lua/nvim-tree/actions/node/open-file.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ local function pick_window()
112112
end
113113
local _, resp = pcall(get_user_input_char)
114114
resp = (resp or ""):upper()
115-
if vim.opt.cmdheight._value ~= 0 then
116-
vim.api.nvim_command "normal! :"
117-
end
115+
utils.clear_prompt()
118116

119117
-- Restore window options
120118
for _, id in ipairs(selectable) do

lua/nvim-tree/marks/bulk-move.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function M.bulk_move()
1212
end
1313

1414
vim.ui.input({ prompt = "Move to: ", default = Core.get_cwd(), completion = "dir" }, function(location)
15+
utils.clear_prompt()
1516
if not location or location == "" then
1617
return
1718
end

lua/nvim-tree/utils.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,10 @@ function M.get_win_buf_from_path(path)
373373
return nil, nil
374374
end
375375

376+
function M.clear_prompt()
377+
if vim.opt.cmdheight._value ~= 0 then
378+
vim.cmd "normal! :"
379+
end
380+
end
381+
376382
return M

0 commit comments

Comments
 (0)