feat(#1804): add api.marks.bulk.delete with default bd mapping (#2276)

This commit is contained in:
Alexander Courtis
2023-06-18 14:09:11 +10:00
committed by GitHub
parent d4f6d33496
commit bdceaf5096
8 changed files with 93 additions and 24 deletions

View File

@@ -0,0 +1,52 @@
local marks = require "nvim-tree.marks"
local utils = require "nvim-tree.utils"
local remove_file = require "nvim-tree.actions.fs.remove-file"
local notify = require "nvim-tree.notify"
local lib = require "nvim-tree.lib"
local M = {
config = {},
}
--- Delete nodes; each removal will be optionally notified
--- @param nodes table
local function do_delete(nodes)
for _, node in pairs(nodes) do
remove_file.remove(node)
end
marks.clear_marks()
if not M.config.filesystem_watchers.enable then
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end
--- Delete marked nodes, optionally prompting
function M.bulk_delete()
local nodes = marks.get_marks()
if not nodes or #nodes == 0 then
notify.warn "No bookmarksed to delete."
return
end
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)
utils.clear_prompt()
if item_short == "y" then
do_delete(nodes)
end
end)
else
do_delete(nodes)
end
end
function M.setup(opts)
M.config.ui = opts.ui
M.config.filesystem_watchers = opts.filesystem_watchers
end
return M

View File

@@ -1,7 +1,7 @@
local Marks = require "nvim-tree.marks"
local Core = require "nvim-tree.core"
local marks = require "nvim-tree.marks"
local core = require "nvim-tree.core"
local utils = require "nvim-tree.utils"
local FsRename = require "nvim-tree.actions.fs.rename-file"
local rename_file = require "nvim-tree.actions.fs.rename-file"
local notify = require "nvim-tree.notify"
local M = {
@@ -9,12 +9,12 @@ local M = {
}
function M.bulk_move()
if #Marks.get_marks() == 0 then
notify.warn "no bookmark to perform bulk move on, aborting."
if #marks.get_marks() == 0 then
notify.warn "No bookmarks to move."
return
end
vim.ui.input({ prompt = "Move to: ", default = Core.get_cwd(), completion = "dir" }, function(location)
vim.ui.input({ prompt = "Move to: ", default = core.get_cwd(), completion = "dir" }, function(location)
utils.clear_prompt()
if not location or location == "" then
return
@@ -24,13 +24,15 @@ function M.bulk_move()
return
end
local marks = Marks.get_marks()
for _, node in pairs(marks) do
local nodes = marks.get_marks()
for _, node in pairs(nodes) do
local head = vim.fn.fnamemodify(node.absolute_path, ":t")
local to = utils.path_join { location, head }
FsRename.rename(node, to)
rename_file.rename(node, to)
end
marks.clear_marks()
if not M.config.filesystem_watchers.enable then
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end

View File

@@ -75,6 +75,7 @@ end
function M.setup(opts)
vim.fn.sign_define(SIGN_NAME, { text = opts.renderer.icons.glyphs.bookmark, texthl = "NvimTreeBookmark" })
require("nvim-tree.marks.bulk-delete").setup(opts)
require("nvim-tree.marks.bulk-move").setup(opts)
end