mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(picker.undo): cleanup tmp files in async:on("done"). Closes #2434
This commit is contained in:
parent
53d8012e5e
commit
3038dac460
1 changed files with 10 additions and 4 deletions
|
|
@ -382,6 +382,7 @@ function M.undo(opts, ctx)
|
|||
local buf = vim.api.nvim_get_current_buf()
|
||||
local file = vim.api.nvim_buf_get_name(buf)
|
||||
local items = {} ---@type snacks.picker.finder.Item[]
|
||||
local diff_fn = vim.text and vim.text.diff or vim.diff
|
||||
|
||||
-- Copy the current buffer to a temporary file and load the undo history.
|
||||
-- This is done to prevent the current buffer from being modified,
|
||||
|
|
@ -417,7 +418,7 @@ function M.undo(opts, ctx)
|
|||
end)
|
||||
vim.o.eventignore = ei
|
||||
|
||||
local diff = vim.diff(table.concat(before, "\n") .. "\n", table.concat(after, "\n") .. "\n", opts.diff) --[[@as string]]
|
||||
local diff = diff_fn(table.concat(before, "\n") .. "\n", table.concat(after, "\n") .. "\n", opts.diff) --[[@as string]]
|
||||
local changes = {} ---@type string[]
|
||||
local added_lines = {} ---@type string[]
|
||||
local removed_lines = {} ---@type string[]
|
||||
|
|
@ -479,6 +480,14 @@ function M.undo(opts, ctx)
|
|||
---@param cb async fun(item: snacks.picker.finder.Item)
|
||||
---@async
|
||||
return function(cb)
|
||||
ctx.async:on("done", function()
|
||||
vim.schedule(function()
|
||||
-- Clean up the temporary files
|
||||
vim.api.nvim_buf_delete(tmpbuf, { force = true })
|
||||
vim.fn.delete(tmp_file)
|
||||
vim.fn.delete(tmp_undo)
|
||||
end)
|
||||
end)
|
||||
for i = #items, 1, -1 do
|
||||
cb(items[i])
|
||||
end
|
||||
|
|
@ -495,9 +504,6 @@ function M.undo(opts, ctx)
|
|||
end)
|
||||
ctx.async:suspend()
|
||||
end
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_buf_delete(tmpbuf, { force = true })
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue