diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index d02e0044b6e..e3923baf021 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -47,8 +47,9 @@ CONTENTS *nvim-tree* 7.1 Mappings: Default |nvim-tree-mappings-default| 8. Highlight |nvim-tree-highlight| 9. Events |nvim-tree-events| - 10. OS Specific Restrictions |nvim-tree-os-specific| - 11. Netrw |nvim-tree-netrw| + 10. Prompts |nvim-tree-prompts| + 11. OS Specific Restrictions |nvim-tree-os-specific| + 12. Netrw |nvim-tree-netrw| ============================================================================== 1. INTRODUCTION *nvim-tree-introduction* @@ -2442,7 +2443,32 @@ Example subscription: > }) < ============================================================================== - 10. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific* + 10. PROMPTS *nvim-tree-prompts* + +Some NvimTree actions use the builtin |vim.ui.select| prompt API for +confirmations when the |nvim_tree.select_prompts| option is set. + +The API accepts the optional `kind` key as part of the {opts} parameter, which +can can be used to identify the type of prompt, to allow user side +configurations for different types of prompts. + +- `nvimtree_overwrite_rename` + overwrite or rename during |nvim-tree-api.fs.paste()| + +- `nvimtree_remove` + delete during |nvim-tree-api.fs.remove()| + +- `nvimtree_trash` + send to trash during |nvim-tree-api.fs.trash()| + +- `nvimtree_bulk_delete` + delete all bookmarked during |nvim-tree-api.marks.bulk.delete()| + +- `nvimtree_bulk_trash` + send all bookmarked to trash during |nvim-tree-api.marks.bulk.trash()| + +============================================================================== + 11. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific* macOS - Rename to different case is not possible when using a case insensitive file @@ -2455,7 +2481,7 @@ Windows WSL and PowerShell - Some filesystem watcher error related to permissions will not be reported ============================================================================== - 11. NETRW *nvim-tree-netrw* + 12. NETRW *nvim-tree-netrw* |netrw| is a standard neovim plugin that is enabled by default. It provides, amongst other functionality, a file/directory browser. diff --git a/lua/nvim-tree/actions/fs/copy-paste.lua b/lua/nvim-tree/actions/fs/copy-paste.lua index a342d8bee37..dc2902c7e10 100644 --- a/lua/nvim-tree/actions/fs/copy-paste.lua +++ b/lua/nvim-tree/actions/fs/copy-paste.lua @@ -131,7 +131,7 @@ local function do_single_paste(source, dest, action_type, action_fn) else local prompt_select = "Overwrite " .. dest .. " ?" local prompt_input = prompt_select .. " R(ename)/y/n: " - lib.prompt(prompt_input, prompt_select, { "", "y", "n" }, { "Rename", "Yes", "No" }, function(item_short) + lib.prompt(prompt_input, prompt_select, { "", "y", "n" }, { "Rename", "Yes", "No" }, "nvimtree_overwrite_rename", function(item_short) utils.clear_prompt() if item_short == "y" then on_process() diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index 3d55bff573b..36288e100b9 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -130,7 +130,7 @@ function M.fn(node) items_long = { "No", "Yes" } end - lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short) + lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_remove", function(item_short) utils.clear_prompt() if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then do_remove() diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index 82449bd2745..f381022cfa3 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -102,7 +102,7 @@ function M.fn(node) items_long = { "No", "Yes" } end - lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short) + lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_trash", function(item_short) utils.clear_prompt() if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then do_trash() diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index 8a383cbb4ce..848bdeeff63 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -157,8 +157,9 @@ end ---@param prompt_select string ---@param items_short string[] ---@param items_long string[] +---@param kind string|nil ---@param callback fun(item_short: string) -function M.prompt(prompt_input, prompt_select, items_short, items_long, callback) +function M.prompt(prompt_input, prompt_select, items_short, items_long, kind, callback) local function format_item(short) for i, s in ipairs(items_short) do if short == s then @@ -169,7 +170,7 @@ function M.prompt(prompt_input, prompt_select, items_short, items_long, callback end if M.select_prompts then - vim.ui.select(items_short, { prompt = prompt_select, format_item = format_item }, function(item_short) + vim.ui.select(items_short, { prompt = prompt_select, kind = kind, format_item = format_item }, function(item_short) callback(item_short) end) else diff --git a/lua/nvim-tree/marks/bulk-delete.lua b/lua/nvim-tree/marks/bulk-delete.lua index 3e27565d139..aff06752953 100644 --- a/lua/nvim-tree/marks/bulk-delete.lua +++ b/lua/nvim-tree/marks/bulk-delete.lua @@ -33,7 +33,7 @@ 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" }, { "No", "Yes" }, function(item_short) + lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, "nvimtree_bulk_delete", function(item_short) utils.clear_prompt() if item_short == "y" then do_delete(nodes) diff --git a/lua/nvim-tree/marks/bulk-trash.lua b/lua/nvim-tree/marks/bulk-trash.lua index 93c47d3eb96..fd2a5c3fbcb 100644 --- a/lua/nvim-tree/marks/bulk-trash.lua +++ b/lua/nvim-tree/marks/bulk-trash.lua @@ -28,7 +28,7 @@ function M.bulk_trash() if M.config.ui.confirm.trash then local prompt_select = "Trash bookmarked ?" local prompt_input = prompt_select .. " y/N: " - lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short) + lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, "nvimtree_bulk_trash", function(item_short) utils.clear_prompt() if item_short == "y" then do_trash(nodes)