feat(blame): show commit's hunk in the line popup
This commit is contained in:
@@ -608,6 +608,32 @@ t.test("preview_hunk shows the hunk body without file headers", function()
|
||||
end
|
||||
end)
|
||||
|
||||
t.test("preview_hunk highlights diff lines via per-line extmarks", function()
|
||||
local _, buf = setup("a\nb\nc\n", "a\nB\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
vim.api.nvim_win_set_cursor(0, { 2, 0 })
|
||||
hunks.preview_hunk(buf)
|
||||
local float = assert(find_float(), "preview float should open")
|
||||
t.defer(function()
|
||||
pcall(vim.api.nvim_win_close, float, true)
|
||||
end)
|
||||
local pbuf = vim.api.nvim_win_get_buf(float)
|
||||
local seen = {} ---@type table<string, boolean>
|
||||
for _, m in
|
||||
ipairs(vim.api.nvim_buf_get_extmarks(pbuf, -1, 0, -1, {
|
||||
details = true,
|
||||
}))
|
||||
do
|
||||
local hl = m[4] and m[4].line_hl_group
|
||||
if hl then
|
||||
seen[hl] = true
|
||||
end
|
||||
end
|
||||
t.truthy(seen["GitHunkHeader"], "@@ header gets GitHunkHeader")
|
||||
t.truthy(seen["GitHunkAdded"], "+ line gets GitHunkAdded")
|
||||
t.truthy(seen["GitHunkRemoved"], "- line gets GitHunkRemoved")
|
||||
end)
|
||||
|
||||
t.test("preview_hunk re-invocation focuses the open float", function()
|
||||
local _, buf = setup("a\nb\nc\n", "a\nB\nc\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
|
||||
Reference in New Issue
Block a user