From 920868dba13466586897a8f40220eca6b2caac41 Mon Sep 17 00:00:00 2001 From: Mohamed Arish <69137941+mohamedarish@users.noreply.github.com> Date: Sun, 20 Aug 2023 13:04:14 +0530 Subject: [PATCH] fix(#2370): Better "y/N" prompts (#2377) * Changed the default y/n prompt to default to N in most cases(all delete cases) and made it so that the copy paste same name conflict defaults to R(ename) * Removed all No conditions as they are not used and not needed * Made item_short into lowercase and also fixed prompts in dressing.nvim and telescope-select.nvim * Fixed the exception which occurs on pressing esc in the prompt and also made rename to be blank or r.*/R.* --- lua/nvim-tree/actions/fs/copy-paste.lua | 6 +++--- lua/nvim-tree/actions/fs/remove-file.lua | 4 ++-- lua/nvim-tree/actions/fs/trash.lua | 4 ++-- lua/nvim-tree/lib.lua | 4 +++- lua/nvim-tree/marks/bulk-delete.lua | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lua/nvim-tree/actions/fs/copy-paste.lua b/lua/nvim-tree/actions/fs/copy-paste.lua index 6c339dc0..1b26ef12 100644 --- a/lua/nvim-tree/actions/fs/copy-paste.lua +++ b/lua/nvim-tree/actions/fs/copy-paste.lua @@ -110,12 +110,12 @@ local function do_single_paste(source, dest, action_type, action_fn) end) else local prompt_select = "Overwrite " .. dest .. " ?" - local prompt_input = prompt_select .. " y/n/r(ename): " - lib.prompt(prompt_input, prompt_select, { "y", "n", "r" }, { "Yes", "No", "Rename" }, function(item_short) + local prompt_input = prompt_select .. " R(ename)/y/n: " + lib.prompt(prompt_input, prompt_select, { "", "y", "n" }, { "Rename", "Yes", "No" }, function(item_short) utils.clear_prompt() if item_short == "y" then on_process() - elseif item_short == "r" then + elseif item_short == "" or item_short == "r" then vim.ui.input({ prompt = "Rename to ", default = dest, completion = "dir" }, function(new_dest) utils.clear_prompt() if new_dest then diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index d29bd21c..abc94d4f 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -107,8 +107,8 @@ function M.fn(node) 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", "n" }, { "Yes", "No" }, function(item_short) + local prompt_input = prompt_select .. " y/N: " + lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short) utils.clear_prompt() if item_short == "y" then do_remove() diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index 00124108..1db48a20 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -83,8 +83,8 @@ function M.fn(node) 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", "n" }, { "Yes", "No" }, function(item_short) + local prompt_input = prompt_select .. " y/N: " + lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short) utils.clear_prompt() if item_short == "y" then do_trash() diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index 622bf8db..66ab0ed5 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -148,7 +148,9 @@ function M.prompt(prompt_input, prompt_select, items_short, items_long, callback end) else vim.ui.input({ prompt = prompt_input, default = items_short[1] or "" }, function(item_short) - callback(item_short and item_short:sub(1, 1) or nil) + if item_short then + callback(string.lower(item_short and item_short:sub(1, 1)) or nil) + end end) end end diff --git a/lua/nvim-tree/marks/bulk-delete.lua b/lua/nvim-tree/marks/bulk-delete.lua index 3dd38ea9..7a9cb5a0 100644 --- a/lua/nvim-tree/marks/bulk-delete.lua +++ b/lua/nvim-tree/marks/bulk-delete.lua @@ -32,8 +32,8 @@ function M.bulk_delete() if M.config.ui.confirm.remove then local prompt_select = "Remove bookmarked ?" - local prompt_input = prompt_select .. " y/n: " - lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short) + local prompt_input = prompt_select .. " y/N: " + lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short) utils.clear_prompt() if item_short == "y" then do_delete(nodes)