Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 62 additions & 9 deletions lua/gitsigns/actions/blame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ local function get_hash_color(sha)
return hl_name
end

--- Create a right-side extmark for the blame heatmap
--- @param bufnr integer
--- @param lnum integer (1-indexed)
--- @param win_width integer
--- @param min_time integer
--- @param max_time integer
--- @param author_time integer
local function set_right_extmark(bufnr, lnum, win_width, min_time, max_time, author_time)
api.nvim_buf_set_extmark(bufnr, ns, lnum - 1, 0, {
virt_text_win_col = win_width,
virt_text = {
{
'┃',
get_temp_hl(min_time, max_time, author_time, 0.5, true),
},
},
})
end

---@param amount integer
---@param text string
---@return string
Expand Down Expand Up @@ -137,15 +156,7 @@ local function render(blame, win, main_win, buf_sha)
hl_group = hash_hl,
})

api.nvim_buf_set_extmark(bufnr, ns, i - 1, 0, {
virt_text_win_col = win_width,
virt_text = {
{
'┃',
get_temp_hl(min_time, max_time, blame_info.commit.author_time, 0.5, true),
},
},
})
set_right_extmark(bufnr, i, win_width, min_time, max_time, blame_info.commit.author_time)

if not commit_lines[i] then
api.nvim_buf_set_extmark(bufnr, ns, i - 1, 2, {
Expand Down Expand Up @@ -314,6 +325,38 @@ local function diff(bufnr, blm_win, blame)
end
end

--- Update the right-side extmarks when the window is resized
--- @param blm_bufnr integer
--- @param blm_win integer
--- @param entries table<integer,Gitsigns.BlameInfo?>
--- @param min_time integer
--- @param max_time integer
local function update_right_extmarks(blm_bufnr, blm_win, entries, min_time, max_time)
if not api.nvim_win_is_valid(blm_win) or not api.nvim_buf_is_valid(blm_bufnr) then
return
end

-- Get the actual window width (not the content width)
-- Subtract 1 because virt_text_win_col is 0-indexed
local win_width = api.nvim_win_get_width(blm_win) - 1

-- Get all extmarks and delete only those with virt_text_win_col
-- These are the right-side heatmap indicators that need repositioning
local extmarks = api.nvim_buf_get_extmarks(blm_bufnr, ns, 0, -1, { details = true })

for _, ext in ipairs(extmarks) do
local id, row, col, details = ext[1], ext[2], ext[3], ext[4]
if details.virt_text_win_col then
api.nvim_buf_del_extmark(blm_bufnr, ns, id)
end
end

-- Recreate the right-side extmarks with updated position
for i, blame_info in ipairs(entries) do
set_right_extmark(blm_bufnr, i, win_width, min_time, max_time, blame_info.commit.author_time)
end
end

--- @param mode string
--- @param lhs string
--- @param cb fun()
Expand Down Expand Up @@ -481,6 +524,16 @@ function M.blame(opts)
end,
})

-- Update right-side extmarks on window resize
api.nvim_create_autocmd('WinResized', {
buffer = blm_bufnr,
group = group,
callback = function()
local min_time, max_time = assert(cache[bufnr]):get_blame_times()
update_right_extmarks(blm_bufnr, blm_win, blame.entries, min_time, max_time)
end,
})

api.nvim_create_autocmd('WinClosed', {
pattern = tostring(blm_win),
group = group,
Expand Down
Loading