fix(blame): update current_line_blame when attaching

This commit is contained in:
Lewis Russell 2024-06-21 15:21:24 +01:00
parent d03a1c9a10
commit 8df63f2ddc
2 changed files with 41 additions and 38 deletions

View file

@ -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.

View file

@ -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