Skip to content

Commit

Permalink
feat(picker.undo): make diff opts for undo configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Feb 2, 2025
1 parent 8368176 commit d61fb45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lua/snacks/picker/config/sources.lua
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,21 @@ M.spelling = {
confirm = "item_action",
}

---@class snacks.picker.undo.Config: snacks.picker.Config
---@field diff? vim.diff.Opts
M.undo = {
finder = "vim_undo",
format = "undo",
preview = "preview",
confirm = "item_action",
win = { preview = { wo = { number = false, relativenumber = false, signcolumn = "no" } } },
icons = { tree = { last = "┌╴" } }, -- the tree is upside down
diff = {
ctxlen = 4,
ignore_cr_at_eol = true,
ignore_whitespace_change_at_eol = true,
indent_heuristic = true,
},
}

-- Open a project from zoxide
Expand Down
3 changes: 2 additions & 1 deletion lua/snacks/picker/source/vim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ function M.spelling()
return items
end

---@param opts snacks.picker.undo.Config
---@type snacks.picker.finder
function M.undo(opts, ctx)
local tree = vim.fn.undotree()
Expand Down Expand Up @@ -374,7 +375,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", { ctxlen = 4 }) --[[@as string]]
local diff = vim.diff(table.concat(before, "\n"), table.concat(after, "\n"), opts.diff) --[[@as string]]
local changes = {} ---@type string[]
local added, removed = 0, 0

Expand Down

0 comments on commit d61fb45

Please sign in to comment.