Skip to content

Commit dc839a7

Browse files
feat: add kind param to vim.ui.select function calls (#2602)
* feat: add kind param to vim.ui.select function calls * feat: add kind param to prompts for bookmark actions * docs: add section for prompts * docs: add section for prompts --------- Co-authored-by: Alexander Courtis <[email protected]>
1 parent 02ae523 commit dc839a7

File tree

7 files changed

+38
-11
lines changed

7 files changed

+38
-11
lines changed

doc/nvim-tree-lua.txt

+30-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ CONTENTS *nvim-tree*
4747
7.1 Mappings: Default |nvim-tree-mappings-default|
4848
8. Highlight |nvim-tree-highlight|
4949
9. Events |nvim-tree-events|
50-
10. OS Specific Restrictions |nvim-tree-os-specific|
51-
11. Netrw |nvim-tree-netrw|
50+
10. Prompts |nvim-tree-prompts|
51+
11. OS Specific Restrictions |nvim-tree-os-specific|
52+
12. Netrw |nvim-tree-netrw|
5253

5354
==============================================================================
5455
1. INTRODUCTION *nvim-tree-introduction*
@@ -2442,7 +2443,32 @@ Example subscription: >
24422443
})
24432444
<
24442445
==============================================================================
2445-
10. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific*
2446+
10. PROMPTS *nvim-tree-prompts*
2447+
2448+
Some NvimTree actions use the builtin |vim.ui.select| prompt API for
2449+
confirmations when the |nvim_tree.select_prompts| option is set.
2450+
2451+
The API accepts the optional `kind` key as part of the {opts} parameter, which
2452+
can can be used to identify the type of prompt, to allow user side
2453+
configurations for different types of prompts.
2454+
2455+
- `nvimtree_overwrite_rename`
2456+
overwrite or rename during |nvim-tree-api.fs.paste()|
2457+
2458+
- `nvimtree_remove`
2459+
delete during |nvim-tree-api.fs.remove()|
2460+
2461+
- `nvimtree_trash`
2462+
send to trash during |nvim-tree-api.fs.trash()|
2463+
2464+
- `nvimtree_bulk_delete`
2465+
delete all bookmarked during |nvim-tree-api.marks.bulk.delete()|
2466+
2467+
- `nvimtree_bulk_trash`
2468+
send all bookmarked to trash during |nvim-tree-api.marks.bulk.trash()|
2469+
2470+
==============================================================================
2471+
11. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific*
24462472

24472473
macOS
24482474
- Rename to different case is not possible when using a case insensitive file
@@ -2455,7 +2481,7 @@ Windows WSL and PowerShell
24552481
- Some filesystem watcher error related to permissions will not be reported
24562482

24572483
==============================================================================
2458-
11. NETRW *nvim-tree-netrw*
2484+
12. NETRW *nvim-tree-netrw*
24592485

24602486
|netrw| is a standard neovim plugin that is enabled by default. It provides,
24612487
amongst other functionality, a file/directory browser.

lua/nvim-tree/actions/fs/copy-paste.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ local function do_single_paste(source, dest, action_type, action_fn)
131131
else
132132
local prompt_select = "Overwrite " .. dest .. " ?"
133133
local prompt_input = prompt_select .. " R(ename)/y/n: "
134-
lib.prompt(prompt_input, prompt_select, { "", "y", "n" }, { "Rename", "Yes", "No" }, function(item_short)
134+
lib.prompt(prompt_input, prompt_select, { "", "y", "n" }, { "Rename", "Yes", "No" }, "nvimtree_overwrite_rename", function(item_short)
135135
utils.clear_prompt()
136136
if item_short == "y" then
137137
on_process()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function M.fn(node)
130130
items_long = { "No", "Yes" }
131131
end
132132

133-
lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short)
133+
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_remove", function(item_short)
134134
utils.clear_prompt()
135135
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
136136
do_remove()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function M.fn(node)
102102
items_long = { "No", "Yes" }
103103
end
104104

105-
lib.prompt(prompt_input, prompt_select, items_short, items_long, function(item_short)
105+
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_trash", function(item_short)
106106
utils.clear_prompt()
107107
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
108108
do_trash()

lua/nvim-tree/lib.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ end
157157
---@param prompt_select string
158158
---@param items_short string[]
159159
---@param items_long string[]
160+
---@param kind string|nil
160161
---@param callback fun(item_short: string)
161-
function M.prompt(prompt_input, prompt_select, items_short, items_long, callback)
162+
function M.prompt(prompt_input, prompt_select, items_short, items_long, kind, callback)
162163
local function format_item(short)
163164
for i, s in ipairs(items_short) do
164165
if short == s then
@@ -169,7 +170,7 @@ function M.prompt(prompt_input, prompt_select, items_short, items_long, callback
169170
end
170171

171172
if M.select_prompts then
172-
vim.ui.select(items_short, { prompt = prompt_select, format_item = format_item }, function(item_short)
173+
vim.ui.select(items_short, { prompt = prompt_select, kind = kind, format_item = format_item }, function(item_short)
173174
callback(item_short)
174175
end)
175176
else

lua/nvim-tree/marks/bulk-delete.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function M.bulk_delete()
3333
if M.config.ui.confirm.remove then
3434
local prompt_select = "Remove bookmarked ?"
3535
local prompt_input = prompt_select .. " y/N: "
36-
lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short)
36+
lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, "nvimtree_bulk_delete", function(item_short)
3737
utils.clear_prompt()
3838
if item_short == "y" then
3939
do_delete(nodes)

lua/nvim-tree/marks/bulk-trash.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function M.bulk_trash()
2828
if M.config.ui.confirm.trash then
2929
local prompt_select = "Trash bookmarked ?"
3030
local prompt_input = prompt_select .. " y/N: "
31-
lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, function(item_short)
31+
lib.prompt(prompt_input, prompt_select, { "", "y" }, { "No", "Yes" }, "nvimtree_bulk_trash", function(item_short)
3232
utils.clear_prompt()
3333
if item_short == "y" then
3434
do_trash(nodes)

0 commit comments

Comments
 (0)