mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
fix(picker.explorer): do LSP stuff on move
This commit is contained in:
parent
8075530f9b
commit
894ff74930
1 changed files with 27 additions and 24 deletions
|
@ -305,6 +305,33 @@ M.actions = {
|
|||
end,
|
||||
})
|
||||
end,
|
||||
explorer_move = function(picker)
|
||||
local state = M.get_state(picker)
|
||||
---@type string[]
|
||||
local paths = vim.tbl_map(Snacks.picker.util.path, picker:selected())
|
||||
if #paths == 0 then
|
||||
Snacks.notify.warn("No files selected to move")
|
||||
return
|
||||
end
|
||||
local target = state:dir()
|
||||
local what = #paths == 1 and vim.fn.fnamemodify(paths[1], ":p:~:.") or #paths .. " files"
|
||||
local t = vim.fn.fnamemodify(target, ":p:~:.")
|
||||
|
||||
Snacks.picker.select({ "Yes", "No" }, { prompt = "Move " .. what .. " to " .. t .. "?" }, function(_, idx)
|
||||
if idx == 1 then
|
||||
for _, from in ipairs(paths) do
|
||||
local to = target .. "/" .. vim.fn.fnamemodify(from, ":t")
|
||||
Snacks.rename.on_rename_file(from, to, function()
|
||||
local ok, err = pcall(vim.fn.rename, from, to)
|
||||
if not ok then
|
||||
Snacks.notify.error("Failed to move `" .. from .. "`:\n- " .. err)
|
||||
end
|
||||
end)
|
||||
end
|
||||
state:update()
|
||||
end
|
||||
end)
|
||||
end,
|
||||
explorer_copy = function(picker, item)
|
||||
if not item then
|
||||
return
|
||||
|
@ -356,30 +383,6 @@ M.actions = {
|
|||
end
|
||||
end)
|
||||
end,
|
||||
explorer_move = function(picker)
|
||||
local state = M.get_state(picker)
|
||||
---@type string[]
|
||||
local paths = vim.tbl_map(Snacks.picker.util.path, picker:selected())
|
||||
if #paths == 0 then
|
||||
Snacks.notify.warn("No files selected to move")
|
||||
return
|
||||
end
|
||||
local to = state:dir()
|
||||
local what = #paths == 1 and vim.fn.fnamemodify(paths[1], ":p:~:.") or #paths .. " files"
|
||||
local t = vim.fn.fnamemodify(to, ":p:~:.")
|
||||
|
||||
Snacks.picker.select({ "Yes", "No" }, { prompt = "Move " .. what .. " to " .. t .. "?" }, function(_, idx)
|
||||
if idx == 1 then
|
||||
for _, path in ipairs(paths) do
|
||||
local ok, err = pcall(vim.fn.rename, path, to .. "/" .. vim.fn.fnamemodify(path, ":t"))
|
||||
if not ok then
|
||||
Snacks.notify.error("Failed to move `" .. path .. "`:\n- " .. err)
|
||||
end
|
||||
end
|
||||
state:update()
|
||||
end
|
||||
end)
|
||||
end,
|
||||
explorer_focus = function(picker)
|
||||
local state = M.get_state(picker)
|
||||
state:set_cwd(state:dir())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue