fix: just ask if overwriting when attaching

to upload content cancel attach and use force share
This commit is contained in:
əlemi 2024-09-26 03:42:29 +02:00
parent 9e48af37fe
commit 2391b3c4fd
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -19,16 +19,12 @@ local ticks = {}
---@param opts AttachOptions options for attaching ---@param opts AttachOptions options for attaching
local function attach(name, opts) local function attach(name, opts)
if not opts.skip_exists_check and vim.fn.bufexists(name) == 1 then if not opts.skip_exists_check and vim.fn.bufexists(name) == 1 then
vim.ui.select( vim.ui.input(
{ "download content", "upload content" }, { prompt = "buffer exists, overwrite?" },
{ prompt = "buffer is already open" },
function (choice) function (choice)
if choice == nil then return end if not vim.startswith(string.lower(choice), "y") then return end
opts.buffer = vim.fn.bufnr(name) opts.buffer = vim.fn.bufnr(name)
opts.skip_exists_check = true opts.skip_exists_check = true
if choice == "upload content" then
opts.content = utils.buffer.get_content(opts.buffer)
end
attach(name, opts) attach(name, opts)
end end
) )
@ -168,9 +164,12 @@ local function detach(name)
local buffer = buffer_id_map[name] local buffer = buffer_id_map[name]
id_buffer_map[buffer] = nil id_buffer_map[buffer] = nil
buffer_id_map[name] = nil buffer_id_map[name] = nil
CODEMP.workspace:detach(name) if not CODEMP.workspace:detach(name) then
print(" /!\\ dangling reference, detach incomplete")
else
print(" -- detached from buffer " .. name)
end
print(" -- detached from buffer " .. name)
require('codemp.window').update() require('codemp.window').update()
end end