fix(picker.diff): move git status calc based on diff to format

This commit is contained in:
Folke Lemaitre 2025-11-03 13:31:40 +01:00
parent 77609a0013
commit b553c18c26
No known key found for this signature in database
GPG key ID: 9B52594D560070AB
2 changed files with 9 additions and 7 deletions

View file

@ -561,12 +561,17 @@ function M.keymap(item, picker)
end
function M.git_status(item, picker)
if not item.status then
local status = item.status
if not status and item.block then
local block = item.block ---@type snacks.picker.diff.Block
status = ({ new = "A", delete = "D", rename = "R", copy = "C" })[block.type] or "M"
status = block.unmerged and (status .. status) or item.staged and (status .. " ") or (" " .. status)
elseif not status then
return M.filename(item, picker)
end
local ret = {} ---@type snacks.picker.Highlight[]
local a = Snacks.picker.util.align
local s = vim.trim(item.status):sub(1, 1)
local s = vim.trim(status):sub(1, 1)
local hls = {
["A"] = "SnacksPickerGitStatusAdded",
["M"] = "SnacksPickerGitStatusModified",
@ -576,8 +581,8 @@ function M.git_status(item, picker)
["?"] = "SnacksPickerGitStatusUntracked",
}
local hl = hls[s] or "SnacksPickerGitStatus"
hl = item.status:sub(1, 1) == "M" and "SnacksPickerGitStatusStaged" or hl
ret[#ret + 1] = { a(item.status, 2, { align = "right" }), hl }
hl = status:sub(1, 1) == "M" and "SnacksPickerGitStatusStaged" or hl
ret[#ret + 1] = { a(status, 2, { align = "right" }), hl }
ret[#ret + 1] = { " " }
if item.rename then
local file = item.file

View file

@ -290,9 +290,6 @@ function M.diff(opts, ctx)
finder(function(item)
if not opts.base then
item.staged = opts.staged or f == 2
local block = item.block ---@type snacks.picker.diff.Block
local status = ({ new = "A", delete = "D", rename = "R", copy = "C" })[block.type] or "M"
item.status = block.unmerged and (status .. status) or item.staged and (status .. " ") or (" " .. status)
end
items[#items + 1] = item
end)