From d61fb453c6c23976759e16a33fd8d6cb79cc59bc Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sun, 2 Feb 2025 09:47:13 +0100 Subject: [PATCH] feat(picker.undo): make diff opts for undo configurable --- lua/snacks/picker/config/sources.lua | 8 ++++++++ lua/snacks/picker/source/vim.lua | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/snacks/picker/config/sources.lua b/lua/snacks/picker/config/sources.lua index 3f562571..645b483f 100644 --- a/lua/snacks/picker/config/sources.lua +++ b/lua/snacks/picker/config/sources.lua @@ -692,6 +692,8 @@ 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", @@ -699,6 +701,12 @@ M.undo = { 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 diff --git a/lua/snacks/picker/source/vim.lua b/lua/snacks/picker/source/vim.lua index 229db20a..d20c8462 100644 --- a/lua/snacks/picker/source/vim.lua +++ b/lua/snacks/picker/source/vim.lua @@ -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() @@ -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