Skip to content

Commit

Permalink
fix: random errors from blame autocommands (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehaertl authored and lewis6991 committed Oct 28, 2024
1 parent ee7634a commit 2d725fd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lua/gitsigns/blame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,19 @@ local function sync_cursors(augroup, wins)
buffer = b,
group = augroup,
callback = function()
cursor_save = unpack(api.nvim_win_get_cursor(w))
if api.nvim_win_is_valid(w) then
cursor_save = unpack(api.nvim_win_get_cursor(w))
end
end,
})

api.nvim_create_autocmd('BufEnter', {
group = augroup,
buffer = b,
callback = function()
if not api.nvim_win_is_valid(w) then
return
end
local cur_cursor, cur_cursor_col = unpack(api.nvim_win_get_cursor(w))
if cursor_save and cursor_save ~= cur_cursor then
api.nvim_win_set_cursor(w, { cursor_save, vim.o.startofline and 0 or cur_cursor_col })
Expand Down Expand Up @@ -402,7 +407,9 @@ M.blame = function()
group = group,
callback = function()
api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
cur_wlo.foldenable, cur_wlo.scrollbind, cur_wlo.wrap = unpack(cur_orig_wlo)
if api.nvim_win_is_valid(win) then
cur_wlo.foldenable, cur_wlo.scrollbind, cur_wlo.wrap = unpack(cur_orig_wlo)
end
end,
})

Expand Down

0 comments on commit 2d725fd

Please sign in to comment.