fix(git): align hunk signs with :diffsplit
This commit is contained in:
+23
-4
@@ -42,15 +42,34 @@ local function resolve_buf(buf)
|
|||||||
return buf and buf ~= 0 and buf or vim.api.nvim_get_current_buf()
|
return buf and buf ~= 0 and buf or vim.api.nvim_get_current_buf()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Mirror the hunk-affecting parts of the user's 'diffopt' so the gutter
|
||||||
|
---lines up with what `:diffsplit` shows.
|
||||||
|
---@return table
|
||||||
|
local function diff_opts()
|
||||||
|
local opts = { result_type = "indices", algorithm = "myers" }
|
||||||
|
for _, item in ipairs(vim.split(vim.o.diffopt, ",", { plain = true })) do
|
||||||
|
if item == "indent-heuristic" then
|
||||||
|
opts.indent_heuristic = true
|
||||||
|
else
|
||||||
|
local algorithm = item:match("^algorithm:(.+)$")
|
||||||
|
if algorithm then
|
||||||
|
opts.algorithm = algorithm
|
||||||
|
end
|
||||||
|
local linematch = item:match("^linematch:(%d+)$")
|
||||||
|
if linematch then
|
||||||
|
opts.linematch = tonumber(linematch)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return opts
|
||||||
|
end
|
||||||
|
|
||||||
---@param state ow.Git.Hunks.BufState
|
---@param state ow.Git.Hunks.BufState
|
||||||
---@param new_lines string[]
|
---@param new_lines string[]
|
||||||
local function compute_hunks(state, new_lines)
|
local function compute_hunks(state, new_lines)
|
||||||
local old = table.concat(state.index or {}, "\n")
|
local old = table.concat(state.index or {}, "\n")
|
||||||
local new = table.concat(new_lines, "\n")
|
local new = table.concat(new_lines, "\n")
|
||||||
local raw = vim.text.diff(old, new, {
|
local raw = vim.text.diff(old, new, diff_opts())
|
||||||
result_type = "indices",
|
|
||||||
algorithm = "histogram",
|
|
||||||
})
|
|
||||||
---@type ow.Git.Hunks.Hunk[]
|
---@type ow.Git.Hunks.Hunk[]
|
||||||
local hunks = {}
|
local hunks = {}
|
||||||
if type(raw) ~= "table" then
|
if type(raw) ~= "table" then
|
||||||
|
|||||||
Reference in New Issue
Block a user