Skip to content

feat(#2498): add option for "Y/n" prompts #2500

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 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
confirm = {
remove = true,
trash = true,
default_yes = false,
},
},
experimental = {},
Expand Down Expand Up @@ -1459,6 +1460,10 @@ Confirmation prompts.
Prompt before trashing.
Type: `boolean`, Default: `true`

*nvim-tree.ui.confirm.default_yes*
If `true` the prompt will be `"Y/n"`, otherwise `"y/N"`.
Type: `boolean`, Default: `false`

==============================================================================
5.19 OPTS: EXPERIMENTAL *nvim-tree-opts-experimental*

Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
confirm = {
remove = true,
trash = true,
default_yes = false,
},
},
experimental = {},
Expand Down
19 changes: 15 additions & 4 deletions lua/nvim-tree/actions/fs/remove-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,22 @@ function M.fn(node)
end

if M.config.ui.confirm.remove then
local prompt_select = "Remove " .. node.name .. " ?"
local prompt_input = prompt_select .. " y/N: "
lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short)
local prompt_select = "Remove " .. node.name .. "?"
local prompt_input, items_short, items_long

if M.config.ui.confirm.default_yes then
prompt_input = prompt_select .. " Y/n: "
items_short = { "", "n" }
items_long = { "Yes", "No" }
else
prompt_input = prompt_select .. " y/N: "
items_short = { "", "y" }
items_long = { "No", "Yes" }
end

lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short)
utils.clear_prompt()
if item_short == "y" then
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
do_remove()
end
end)
Expand Down
19 changes: 15 additions & 4 deletions lua/nvim-tree/actions/fs/trash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,22 @@ function M.fn(node)
end

if M.config.ui.confirm.trash then
local prompt_select = "Trash " .. node.name .. " ?"
local prompt_input = prompt_select .. " y/N: "
lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short)
local prompt_select = "Trash " .. node.name .. "?"
local prompt_input, items_short, items_long

if M.config.ui.confirm.default_yes then
prompt_input = prompt_select .. " Y/n: "
items_short = { "", "n" }
items_long = { "Yes", "No" }
else
prompt_input = prompt_select .. " y/N: "
items_short = { "", "y" }
items_long = { "No", "Yes" }
end

lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short)
utils.clear_prompt()
if item_short == "y" then
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
do_trash()
end
end)
Expand Down