Skip to content

Commit c156856

Browse files
feat(#2498): delete, trash prompts default N, added ui.confirm.default_yes option to override this behaviour (#2500)
Co-authored-by: Alexander Courtis <alex@courtis.org>
1 parent 7c5c074 commit c156856

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
573573
confirm = {
574574
remove = true,
575575
trash = true,
576+
default_yes = false,
576577
},
577578
},
578579
experimental = {},
@@ -1459,6 +1460,10 @@ Confirmation prompts.
14591460
Prompt before trashing.
14601461
Type: `boolean`, Default: `true`
14611462

1463+
*nvim-tree.ui.confirm.default_yes*
1464+
If `true` the prompt will be `"Y/n"`, otherwise `"y/N"`.
1465+
Type: `boolean`, Default: `false`
1466+
14621467
==============================================================================
14631468
5.19 OPTS: EXPERIMENTAL *nvim-tree-opts-experimental*
14641469

lua/nvim-tree.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
595595
confirm = {
596596
remove = true,
597597
trash = true,
598+
default_yes = false,
598599
},
599600
},
600601
experimental = {},

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,22 @@ function M.fn(node)
106106
end
107107

108108
if M.config.ui.confirm.remove then
109-
local prompt_select = "Remove " .. node.name .. " ?"
110-
local prompt_input = prompt_select .. " y/N: "
111-
lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short)
109+
local prompt_select = "Remove " .. node.name .. "?"
110+
local prompt_input, items_short, items_long
111+
112+
if M.config.ui.confirm.default_yes then
113+
prompt_input = prompt_select .. " Y/n: "
114+
items_short = { "", "n" }
115+
items_long = { "Yes", "No" }
116+
else
117+
prompt_input = prompt_select .. " y/N: "
118+
items_short = { "", "y" }
119+
items_long = { "No", "Yes" }
120+
end
121+
122+
lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short)
112123
utils.clear_prompt()
113-
if item_short == "y" then
124+
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
114125
do_remove()
115126
end
116127
end)

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,22 @@ function M.fn(node)
8686
end
8787

8888
if M.config.ui.confirm.trash then
89-
local prompt_select = "Trash " .. node.name .. " ?"
90-
local prompt_input = prompt_select .. " y/N: "
91-
lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short)
89+
local prompt_select = "Trash " .. node.name .. "?"
90+
local prompt_input, items_short, items_long
91+
92+
if M.config.ui.confirm.default_yes then
93+
prompt_input = prompt_select .. " Y/n: "
94+
items_short = { "", "n" }
95+
items_long = { "Yes", "No" }
96+
else
97+
prompt_input = prompt_select .. " y/N: "
98+
items_short = { "", "y" }
99+
items_long = { "No", "Yes" }
100+
end
101+
102+
lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short)
92103
utils.clear_prompt()
93-
if item_short == "y" then
104+
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
94105
do_trash()
95106
end
96107
end)

0 commit comments

Comments
 (0)