From c1568568b3f58d5cab87cf6a2a84717afe09d11d Mon Sep 17 00:00:00 2001 From: Azad <49314270+Akmadan23@users.noreply.github.com> Date: Mon, 30 Oct 2023 02:28:29 +0100 Subject: [PATCH] feat(#2498): delete, trash prompts default N, added ui.confirm.default_yes option to override this behaviour (#2500) Co-authored-by: Alexander Courtis --- doc/nvim-tree-lua.txt | 5 +++++ lua/nvim-tree.lua | 1 + lua/nvim-tree/actions/fs/remove-file.lua | 19 +++++++++++++++---- lua/nvim-tree/actions/fs/trash.lua | 19 +++++++++++++++---- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index bf8a4495..92f4ba1f 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -573,6 +573,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. confirm = { remove = true, trash = true, + default_yes = false, }, }, experimental = {}, @@ -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* diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index db420986..d8102989 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -595,6 +595,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS confirm = { remove = true, trash = true, + default_yes = false, }, }, experimental = {}, diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index abc94d4f..76b40b24 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -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) diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index 5f82dd20..41bc8ba0 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -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)