mirror of
https://github.com/nvim-tree/nvim-tree.lua.git
synced 2026-07-28 07:49:46 +05:30
Compare commits
4 Commits
feat/renam
...
c97f42044d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c97f42044d | ||
|
|
4213bd6eab | ||
|
|
f2dd529e3f | ||
|
|
8f73cbb7d2 |
@@ -49,7 +49,7 @@ function M.fn(node)
|
||||
local containing_folder = utils.path_add_trailing(dir.absolute_path)
|
||||
|
||||
local input_opts = {
|
||||
prompt = "Create file ",
|
||||
prompt = "Create ",
|
||||
default = containing_folder,
|
||||
completion = "file",
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ local utils = require("nvim-tree.utils")
|
||||
local events = require("nvim-tree.events")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local config = require("nvim-tree.config")
|
||||
local lib = require("nvim-tree.lib")
|
||||
|
||||
local find_file = require("nvim-tree.actions.finders.find-file").fn
|
||||
|
||||
@@ -48,9 +47,7 @@ end
|
||||
|
||||
---@param node Node
|
||||
---@param to string
|
||||
---@param opts? { notify?: boolean }
|
||||
function M.rename(node, to, opts)
|
||||
opts = opts and opts or {}
|
||||
function M.rename(node, to)
|
||||
local notify_from = notify.render_path(node.absolute_path)
|
||||
local notify_to = notify.render_path(to)
|
||||
|
||||
@@ -95,9 +92,7 @@ function M.rename(node, to, opts)
|
||||
end
|
||||
|
||||
if not is_error then
|
||||
if opts.notify ~= false then
|
||||
notify.info(string.format("%s -> %s", notify_from, notify_to))
|
||||
end
|
||||
notify.info(string.format("%s -> %s", notify_from, notify_to))
|
||||
utils.rename_loaded_buffers(node.absolute_path, to)
|
||||
events._dispatch_node_renamed(node.absolute_path, to)
|
||||
end
|
||||
@@ -197,24 +192,4 @@ function M.rename_full(node)
|
||||
prompt_to_rename(node, ":p")
|
||||
end
|
||||
|
||||
---@param nodes Node[]
|
||||
---@param old_part string
|
||||
---@param new_part string
|
||||
function M.bulk_rename(nodes, old_part, new_part)
|
||||
local prompt_select = string.format("Substitute '%s' for '%s' in %s files?", old_part, new_part, #nodes)
|
||||
|
||||
lib.prompt(prompt_select .. " Y/n: ", prompt_select, ({ "", "y" }), { "No", "Yes" }, "nvimtree_bulk_rename", function(answer)
|
||||
utils.clear_prompt()
|
||||
if answer == "n" then return end
|
||||
|
||||
for _, node in ipairs(nodes) do
|
||||
local new_name = node.name:gsub(old_part, new_part)
|
||||
local new_full_path = vim.fn.fnamemodify(node.absolute_path, ":h") .. "/" .. new_name
|
||||
M.rename(node, new_full_path, { notify = false })
|
||||
end
|
||||
|
||||
notify.info(string.format("%s nodes substituted from %s -> %s", #nodes, old_part, new_part))
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
-- Copyright 2019 Yazdani Kiyan under MIT License
|
||||
local lib = require("nvim-tree.lib")
|
||||
local log = require("nvim-tree.log")
|
||||
local notify = require("nvim-tree.notify")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local full_name = require("nvim-tree.renderer.components.full-name")
|
||||
@@ -94,7 +95,12 @@ local function pick_win_id()
|
||||
return not vim.tbl_contains(selectable, id)
|
||||
end, win_ids)
|
||||
|
||||
if laststatus == 3 then
|
||||
-- experiment only for #3323
|
||||
local clear_not_selectable_statusline = false
|
||||
|
||||
log.line("dev", "clear_unselectable_statusline=%s", clear_not_selectable_statusline)
|
||||
|
||||
if clear_not_selectable_statusline then
|
||||
for _, win_id in ipairs(not_selectable) do
|
||||
local ok_status, statusline = pcall(vim.api.nvim_get_option_value, "statusline", { win = win_id })
|
||||
|
||||
@@ -144,7 +150,7 @@ local function pick_win_id()
|
||||
end
|
||||
end
|
||||
|
||||
if laststatus == 3 then
|
||||
if clear_not_selectable_statusline then
|
||||
for _, id in ipairs(not_selectable) do
|
||||
-- Ensure window still exists at this point
|
||||
if vim.api.nvim_win_is_valid(id) then
|
||||
|
||||
@@ -162,52 +162,6 @@ function M.global()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("CmdlineLeave", {
|
||||
group = augroup_id,
|
||||
pattern = ":",
|
||||
callback = function(ev)
|
||||
if require("nvim-tree.view").get_bufnr() == ev.buf then
|
||||
local cmd = vim.fn.getcmdline()
|
||||
|
||||
if cmd:match("s([^%w])") then
|
||||
local delimiter = cmd:match("s([^%w])")
|
||||
local escaped_delim = delimiter:gsub("[%%%.%+%-%*%?%^%$%(%)%[%]]", "%%%1")
|
||||
|
||||
-- Looks for: s <delimiter> <old> <delimiter> <new> <delimiter or end>
|
||||
local pattern = "s" .. escaped_delim .. "([^" .. escaped_delim .. "]*)" .. escaped_delim .. "([^" .. escaped_delim .. "]*)"
|
||||
|
||||
local old_part, new_part = cmd:match(pattern)
|
||||
|
||||
local core = require("nvim-tree.core")
|
||||
local explorer = core.get_explorer()
|
||||
local utils = require("nvim-tree.utils")
|
||||
local bulk_rename = require("nvim-tree.actions.fs.rename-file").bulk_rename
|
||||
|
||||
local visual_marker = "'<,'>"
|
||||
local nodes = cmd:sub(1, #visual_marker) == visual_marker and
|
||||
utils.get_visual_nodes({ use_native = true, should_exit = false }) or
|
||||
explorer and explorer:get_nodes_by_line(core.get_nodes_starting_line()) or {}
|
||||
local matching_nodes = {}
|
||||
|
||||
for i = #nodes, 1, -1 do
|
||||
local node = nodes[i]
|
||||
if node and node.name:find(old_part) ~= nil then
|
||||
table.insert(matching_nodes, node)
|
||||
end
|
||||
end
|
||||
|
||||
if #matching_nodes > 0 then
|
||||
bulk_rename(matching_nodes, old_part, new_part)
|
||||
else
|
||||
require("nvim-tree.notify").notify(string.format("Not matching nodes with '%s'", old_part))
|
||||
end
|
||||
|
||||
vim.fn.setcmdline("")
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -527,25 +527,19 @@ function M.exit_visual_mode()
|
||||
end
|
||||
|
||||
---Get the visual selection range nodes, exiting visual mode.
|
||||
---@param opts? { should_exit?: boolean, use_native?: boolean }
|
||||
---@return Node[]?
|
||||
function M.get_visual_nodes(opts)
|
||||
opts = opts and opts or {}
|
||||
|
||||
function M.get_visual_nodes()
|
||||
local explorer = require("nvim-tree.core").get_explorer()
|
||||
if not explorer then
|
||||
return nil
|
||||
end
|
||||
local start_line = vim.fn.line(opts.use_native == true and "'<" or "v")
|
||||
local end_line = vim.fn.line(opts.use_native == true and "'>" or ".")
|
||||
local start_line = vim.fn.line("v")
|
||||
local end_line = vim.fn.line(".")
|
||||
if start_line > end_line then
|
||||
start_line, end_line = end_line, start_line
|
||||
end
|
||||
local nodes = explorer:get_nodes_in_range(start_line, end_line)
|
||||
|
||||
if opts.should_exit ~= false then
|
||||
M.exit_visual_mode()
|
||||
end
|
||||
M.exit_visual_mode()
|
||||
return nodes
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user