Skip to content

feat: add kind param to vim.ui.select function calls #2602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/fs/copy-paste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/fs/remove-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/fs/trash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions lua/nvim-tree/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/marks/bulk-delete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/marks/bulk-trash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down