Skip to content

Commit 37d3f72

Browse files
authored
fix: Restore position in blame win when open/close commit info win (#74)
After opening the commit info and pressing 'i' again to go into it, when closing the commit info window the blame window resets to the top of the file. This fix saves the position in the blame window and restores it upon exit from the commit info window.
1 parent d5f4ad5 commit 37d3f72

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lua/blame/commit_info.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@ function CommitInfo:close(cleanup)
2525
then
2626
vim.api.nvim_win_close(self.commit_info_window, true)
2727
end
28+
if self.saved_win and self.saved_pos then
29+
vim.api.nvim_set_current_win(self.saved_win)
30+
vim.api.nvim_win_set_cursor(self.saved_win, self.saved_pos)
31+
end
2832
self.commit_info_window = nil
33+
self.saved_win = nil
34+
self.saved_pos = nil
2935
end
3036

3137
---@param commit Porcelain
3238
function CommitInfo:open(commit)
39+
self.saved_win = vim.api.nvim_get_current_win()
40+
self.saved_pos = vim.api.nvim_win_get_cursor(0)
41+
3342
if self.commit_info_window then
3443
vim.api.nvim_set_current_win(self.commit_info_window)
3544
return
@@ -77,7 +86,7 @@ function CommitInfo:open(commit)
7786

7887
vim.api.nvim_create_autocmd({ "BufHidden", "BufUnload" }, {
7988
callback = function()
80-
self:close(true)
89+
self:close(false)
8190
end,
8291
buffer = info_buf,
8392
group = vim.api.nvim_create_augroup("NvimBlame", { clear = false }),

0 commit comments

Comments
 (0)