Skip to content

Commit 3c51d1f

Browse files
alex-courtischomosukeTelman Babayev
authored
feat: add ui.confirm.remove and ui.confirm.trash, deprecate trash.require_confirm (#1887)
* fix(#1878): nvim frozen on no name buffer when modified.enable (#1879) * feat(api): add api.config.mappings.active, api.config.mappings.default (#1876) * feat(api): add config.mappings.current and config.mappings.default * feat(api): add config.mappings.current and config.mappings.default * feat(api): add config.mappings.current and config.mappings.default * Implement turning off y/n prompt for file deletion * Refactor different prompt configs to single ui table * Remove unused fields * add ui.confirm doc, format/tidy * trash.require_confirm -> ui.confirm.trash * Fix nil value trash field Co-authored-by: Richard Li <38484873+chomosuke@users.noreply.github.com> Co-authored-by: Telman Babayev <babayevtolman@gmail.com>
1 parent 16a0e3c commit 3c51d1f

File tree

5 files changed

+66
-31
lines changed

5 files changed

+66
-31
lines changed

doc/nvim-tree-lua.txt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ Subsequent calls to setup will replace the previous configuration.
374374
},
375375
trash = {
376376
cmd = "gio trash",
377-
require_confirm = true,
378377
},
379378
live_filter = {
380379
prefix = "[FILTER]: ",
@@ -390,6 +389,12 @@ Subsequent calls to setup will replace the previous configuration.
390389
notify = {
391390
threshold = vim.log.levels.INFO,
392391
},
392+
ui = {
393+
confirm = {
394+
remove = true,
395+
trash = true,
396+
},
397+
},
393398
log = {
394399
enable = false,
395400
truncate = false,
@@ -993,10 +998,6 @@ Configuration options for trashing.
993998
The default is shipped with glib2 which is a common linux package.
994999
Type: `string`, Default: `"gio trash"`
9951000

996-
*nvim-tree.trash.require_confirm*
997-
Show a prompt before trashing takes place.
998-
Type: `boolean`, Default: `true`
999-
10001001
*nvim-tree.actions*
10011002
Configuration for various actions.
10021003

@@ -1146,6 +1147,20 @@ Configuration for notification.
11461147
`INFO:` information only e.g. file copy path confirmation.
11471148
`DEBUG:` not used.
11481149

1150+
*nvim-tree.ui*
1151+
General UI configuration.
1152+
1153+
*nvim-tree.ui.confirm*
1154+
Confirmation prompts.
1155+
1156+
*nvim-tree.ui.confirm.remove*
1157+
Prompt before removing.
1158+
Type: `boolean`, Default: `true`
1159+
1160+
*nvim-tree.ui.confirm.trash* (previously `trash.require_confirm`)
1161+
Prompt before trashing.
1162+
Type: `boolean`, Default: `true`
1163+
11491164
*nvim-tree.log*
11501165
Configuration for diagnostic logging.
11511166

lua/nvim-tree.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
698698
},
699699
trash = {
700700
cmd = "gio trash",
701-
require_confirm = true,
702701
},
703702
live_filter = {
704703
prefix = "[FILTER]: ",
@@ -714,6 +713,12 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
714713
notify = {
715714
threshold = vim.log.levels.INFO,
716715
},
716+
ui = {
717+
confirm = {
718+
remove = true,
719+
trash = true,
720+
},
721+
},
717722
log = {
718723
enable = false,
719724
truncate = false,

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

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,45 @@ function M.fn(node)
7373
if node.name == ".." then
7474
return
7575
end
76-
local prompt_select = "Remove " .. node.name .. " ?"
77-
local prompt_input = prompt_select .. " y/n: "
78-
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
79-
utils.clear_prompt()
80-
if item_short == "y" then
81-
if node.nodes ~= nil and not node.link_to then
82-
local success = remove_dir(node.absolute_path)
83-
if not success then
84-
return notify.error("Could not remove " .. node.name)
85-
end
86-
events._dispatch_folder_removed(node.absolute_path)
87-
else
88-
local success = vim.loop.fs_unlink(node.absolute_path)
89-
if not success then
90-
return notify.error("Could not remove " .. node.name)
91-
end
92-
events._dispatch_file_removed(node.absolute_path)
93-
clear_buffer(node.absolute_path)
76+
77+
local function do_remove()
78+
if node.nodes ~= nil and not node.link_to then
79+
local success = remove_dir(node.absolute_path)
80+
if not success then
81+
return notify.error("Could not remove " .. node.name)
9482
end
95-
notify.info(node.absolute_path .. " was properly removed.")
96-
if M.enable_reload then
97-
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
83+
events._dispatch_folder_removed(node.absolute_path)
84+
else
85+
local success = vim.loop.fs_unlink(node.absolute_path)
86+
if not success then
87+
return notify.error("Could not remove " .. node.name)
9888
end
89+
events._dispatch_file_removed(node.absolute_path)
90+
clear_buffer(node.absolute_path)
9991
end
100-
end)
92+
notify.info(node.absolute_path .. " was properly removed.")
93+
if M.enable_reload then
94+
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
95+
end
96+
end
97+
98+
if M.config.ui.confirm.remove then
99+
local prompt_select = "Remove " .. node.name .. " ?"
100+
local prompt_input = prompt_select .. " y/n: "
101+
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
102+
utils.clear_prompt()
103+
if item_short == "y" then
104+
do_remove()
105+
end
106+
end)
107+
else
108+
do_remove()
109+
end
101110
end
102111

103112
function M.setup(opts)
113+
M.config = {}
114+
M.config.ui = opts.ui or {}
104115
M.enable_reload = not opts.filesystem_watchers.enable
105116
M.close_window = opts.actions.remove_file.close_window
106117
end

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ function M.fn(node)
3232
if M.config.trash.cmd == nil then
3333
M.config.trash.cmd = "trash"
3434
end
35-
if M.config.trash.require_confirm == nil then
36-
M.config.trash.require_confirm = true
35+
if M.config.ui.confirm.trash == nil then
36+
M.config.ui.confirm.trash = true
3737
end
3838
else
3939
notify.warn "Trash is currently a UNIX only feature!"
@@ -87,7 +87,7 @@ function M.fn(node)
8787
end
8888
end
8989

90-
if M.config.trash.require_confirm then
90+
if M.config.ui.confirm.trash then
9191
local prompt_select = "Trash " .. node.name .. " ?"
9292
local prompt_input = prompt_select .. " y/n: "
9393
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
@@ -103,6 +103,7 @@ end
103103

104104
function M.setup(opts)
105105
M.config = {}
106+
M.config.ui = opts.ui or {}
106107
M.config.trash = opts.trash or {}
107108
M.enable_reload = not opts.filesystem_watchers.enable
108109
end

lua/nvim-tree/legacy.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ local function refactored(opts)
2727

2828
-- 2023/01/01
2929
utils.move_missing_val(opts, "update_focused_file", "debounce_delay", opts, "view", "debounce_delay", true)
30+
31+
-- 2023/01/08
32+
utils.move_missing_val(opts, "trash", "require_confirm", opts, "ui.confirm", "trash", true)
3033
end
3134

3235
local function removed(opts)

0 commit comments

Comments
 (0)