mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
feat(picker.undo): added ctrl+y to yank added lines from undo
This commit is contained in:
parent
bc087d36d6
commit
811a24cc16
3 changed files with 18 additions and 3 deletions
|
@ -364,11 +364,13 @@ function M.undo(opts, ctx)
|
|||
local diff = vim.diff(table.concat(before, "\n") .. "\n", table.concat(after, "\n") .. "\n", opts.diff) --[[@as string]]
|
||||
local changes = {} ---@type string[]
|
||||
local added, removed = 0, 0
|
||||
local added_lines = {} ---@type string[]
|
||||
|
||||
for _, line in ipairs(vim.split(diff, "\n")) do
|
||||
if line:sub(1, 1) == "+" then
|
||||
added = added + 1
|
||||
changes[#changes + 1] = line:sub(2)
|
||||
added_lines[#added_lines + 1] = line:sub(2)
|
||||
elseif line:sub(1, 1) == "-" then
|
||||
removed = removed + 1
|
||||
changes[#changes + 1] = line:sub(2)
|
||||
|
@ -379,6 +381,7 @@ function M.undo(opts, ctx)
|
|||
{ file = vim.fn.fnamemodify(file, ":."), diff = diff }
|
||||
)
|
||||
item.text = table.concat(changes, " ")
|
||||
item.data = table.concat(added_lines, "\n")
|
||||
item.added = added
|
||||
item.removed = removed
|
||||
item.preview = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue