Skip to content

Commit

Permalink
fix(blame): update current_line_blame when attaching
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Jun 21, 2024
1 parent d03a1c9 commit 8df63f2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
4 changes: 4 additions & 0 deletions lua/gitsigns/attach.lua
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ local attach_throttled = throttle_by_id(function(cbuf, ctx, aucmd)

-- Initial update
manager.update(cbuf)

if config.current_line_blame then
require('gitsigns.current_line_blame').update(cbuf)
end
end)

--- Detach Gitsigns from all buffers it is attached to.
Expand Down
75 changes: 37 additions & 38 deletions lua/gitsigns/current_line_blame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,50 +207,49 @@ end
local update = async.create(1, debounce.throttle_by_id(update0))

--- @type fun(bufnr: integer)
local update_debounced
M.update = nil

function M.setup()
local group = api.nvim_create_augroup('gitsigns_blame', {})

local opts = config.current_line_blame_opts
update_debounced = debounce.debounce_trailing(opts.delay, update)

for k, _ in pairs(cache) do
for k in pairs(cache) do
reset(k)
end

if config.current_line_blame then
local events = { 'FocusGained', 'BufEnter', 'CursorMoved', 'CursorMovedI' }
if vim.fn.exists('#WinResized') == 1 then
-- For nvim 0.9+
events[#events + 1] = 'WinResized'
end

api.nvim_create_autocmd(events, {
group = group,
callback = function(args)
reset(args.buf)
update_debounced(args.buf)
end,
})

api.nvim_create_autocmd({ 'InsertEnter', 'FocusLost', 'BufLeave' }, {
group = group,
callback = function(args)
reset(args.buf)
end,
})

api.nvim_create_autocmd('OptionSet', {
group = group,
pattern = { 'fileformat', 'bomb', 'eol' },
callback = function(args)
reset(args.buf)
end,
})

update_debounced(api.nvim_get_current_buf())
if not config.current_line_blame then
return
end

local group = api.nvim_create_augroup('gitsigns_blame', {})
local opts = config.current_line_blame_opts
M.update = debounce.debounce_trailing(opts.delay, update)

local events = { 'FocusGained', 'BufEnter', 'CursorMoved', 'CursorMovedI' }
if vim.fn.exists('#WinResized') == 1 then
-- For nvim 0.9+
events[#events + 1] = 'WinResized'
end

api.nvim_create_autocmd(events, {
group = group,
callback = function(args)
reset(args.buf)
M.update(args.buf)
end,
})

api.nvim_create_autocmd({ 'InsertEnter', 'FocusLost', 'BufLeave' }, {
group = group,
callback = function(args)
reset(args.buf)
end,
})

api.nvim_create_autocmd('OptionSet', {
group = group,
pattern = { 'fileformat', 'bomb', 'eol' },
callback = function(args)
reset(args.buf)
end,
})
end

return M

0 comments on commit 8df63f2

Please sign in to comment.