feat(blame): show commit's hunk in the line popup

This commit is contained in:
2026-05-26 23:25:08 +02:00
parent 428ded2c4c
commit ff7b20ec46
7 changed files with 589 additions and 65 deletions
+14 -9
View File
@@ -1,3 +1,4 @@
local popup = require("git.core.popup")
local repo = require("git.core.repo")
local util = require("git.core.util")
@@ -5,6 +6,9 @@ local M = {}
local NS_SIGNS = vim.api.nvim_create_namespace("ow.git.hunks")
local NS_OVERLAY = vim.api.nvim_create_namespace("ow.git.hunks.overlay")
local NS_PREVIEW = vim.api.nvim_create_namespace("ow.git.hunks.preview")
local NS_PREVIEW_OVERFLOW =
vim.api.nvim_create_namespace("ow.git.hunks.preview.overflow")
---@alias ow.Git.Hunks.HunkType "add"|"change"|"delete"
@@ -905,16 +909,9 @@ function M.preview_hunk(buf)
local lines = hunk_body(h)
local pbuf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(pbuf, 0, -1, false, lines)
vim.bo[pbuf].filetype = "diff"
vim.bo[pbuf].bufhidden = "wipe"
local width = 0
for _, l in ipairs(lines) do
if #l > width then
width = #l
end
end
width = math.min(math.max(width + 2, 40), vim.o.columns - 4)
local height = math.min(#lines, math.floor(vim.o.lines / 2))
util.paint_diff_lines(pbuf, NS_PREVIEW, lines, 0)
local width, height = popup.size_for(lines, { min_width = 40, padding = 2 })
local win = vim.api.nvim_open_win(pbuf, false, {
relative = "cursor",
row = 1,
@@ -924,6 +921,7 @@ function M.preview_hunk(buf)
style = "minimal",
})
preview_win = win
popup.paint_overflow(pbuf, win, NS_PREVIEW_OVERFLOW)
local function close()
if vim.api.nvim_win_is_valid(win) then
@@ -949,6 +947,13 @@ function M.preview_hunk(buf)
pcall(vim.api.nvim_del_augroup_by_name, "ow.git.hunks.preview")
end,
})
vim.api.nvim_create_autocmd("WinScrolled", {
group = group,
pattern = tostring(win),
callback = function()
popup.paint_overflow(pbuf, win, NS_PREVIEW_OVERFLOW)
end,
})
vim.keymap.set("n", "q", close, { buffer = pbuf, nowait = true })
end