fix: confirm before deleting buffers/workspaces

This commit is contained in:
əlemi 2024-09-15 12:10:19 +02:00
parent b4b2e208f8
commit a0c1fb3acd
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -76,22 +76,28 @@ M.delete = function(state, path, extra)
if selected.type == "root" and vim.startswith(selected.name, "#") then if selected.type == "root" and vim.startswith(selected.name, "#") then
vim.ui.input({ prompt = "disconnect from workspace?" }, function (input) vim.ui.input({ prompt = "disconnect from workspace?" }, function (input)
if input == nil then return end if input == nil then return end
if input ~= "y" then return end if not vim.startswith("y", string.lower(input)) then return end
ws_manager.leave() ws_manager.leave()
manager.refresh("codemp") manager.refresh("codemp")
end) end)
elseif selected.type == "buffer" then elseif selected.type == "buffer" then
if session.workspace == nil then error("join a workspace first") end if session.workspace == nil then error("join a workspace first") end
session.workspace:delete_buffer(selected.name):await() vim.ui.input({ prompt = "delete buffer '" .. selected.name .. "'?" }, function (input)
print("deleted buffer " .. selected.name) if input == nil then return end
manager.refresh("codemp") if not vim.startswith("y", string.lower(input)) then return end
session.workspace:delete_buffer(selected.name):await()
print("deleted buffer " .. selected.name)
manager.refresh("codemp")
end)
elseif selected.type == "workspace" then elseif selected.type == "workspace" then
if session.client == nil then error("connect to server first") end if session.client == nil then error("connect to server first") end
session.client:delete_workspace(selected.name):await() vim.ui.input({ prompt = "delete buffer '" .. selected.name .. "'?" }, function (input)
print("deleted workspace " .. selected.name) if input == nil then return end
manager.refresh("codemp") if not vim.startswith("y", string.lower(input)) then return end
else session.client:delete_workspace(selected.name):await()
print("/!\\ can only delete buffers and workspaces") print("deleted workspace " .. selected.name)
manager.refresh("codemp")
end)
end end
end end