fix(picker.explorer): do LSP stuff on move

This commit is contained in:
Folke Lemaitre 2025-01-31 10:05:42 +01:00
parent 8075530f9b
commit 894ff74930
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -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())