feat(git): add blame side window with synced scroll
This commit is contained in:
@@ -197,6 +197,7 @@ t.test("blame actions are no-ops off a worktree", function()
|
||||
t.quietly(function()
|
||||
blame.line_popup(buf)
|
||||
blame.toggle_inline(buf)
|
||||
blame.toggle_view(buf)
|
||||
end)
|
||||
t.eq(blame.state(buf), nil, "no state created for a non-worktree buffer")
|
||||
end)
|
||||
@@ -300,6 +301,99 @@ t.test("inline annotation follows the cursor", function()
|
||||
t.eq(assert(inline_marks(buf)[1])[2], 2, "annotation moved to line 3")
|
||||
end)
|
||||
|
||||
---@param buf integer
|
||||
---@return integer view_win
|
||||
local function wait_view(buf)
|
||||
local win ---@type integer?
|
||||
t.wait_for(function()
|
||||
for _, w in ipairs(vim.api.nvim_list_wins()) do
|
||||
local b = vim.api.nvim_win_get_buf(w)
|
||||
if b ~= buf and vim.bo[b].filetype == "gitblame" then
|
||||
win = w
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end, "the blame side window to open")
|
||||
return (assert(win))
|
||||
end
|
||||
|
||||
t.test("toggle_view opens and closes a side split", function()
|
||||
local _, buf = setup("alpha\nbeta\ngamma\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
blame.toggle_view(buf)
|
||||
local view_win = wait_view(buf)
|
||||
t.defer(function()
|
||||
if vim.api.nvim_win_is_valid(view_win) then
|
||||
vim.api.nvim_win_close(view_win, true)
|
||||
end
|
||||
end)
|
||||
blame.toggle_view(buf)
|
||||
t.falsy(
|
||||
vim.api.nvim_win_is_valid(view_win),
|
||||
"toggling again closes the view"
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("the side view shows sha, author and an absolute date", function()
|
||||
local dir, buf = setup("alpha\nbeta\ngamma\n")
|
||||
local sha = h.git(dir, "rev-parse", "HEAD").stdout
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
blame.toggle_view(buf)
|
||||
local view_win = wait_view(buf)
|
||||
t.defer(function()
|
||||
if vim.api.nvim_win_is_valid(view_win) then
|
||||
vim.api.nvim_win_close(view_win, true)
|
||||
end
|
||||
end)
|
||||
local view_buf = vim.api.nvim_win_get_buf(view_win)
|
||||
local row = vim.api.nvim_buf_get_lines(view_buf, 0, 1, false)[1] or ""
|
||||
t.truthy(
|
||||
vim.startswith(row, sha:sub(1, 8)),
|
||||
"the row starts with the short sha"
|
||||
)
|
||||
t.truthy(row:find("t", 1, true), "the row includes the author")
|
||||
t.truthy(
|
||||
row:match("%d%d%d%d%-%d%d%-%d%d$"),
|
||||
"the row ends with a YYYY-MM-DD date"
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("<CR> on the view row opens the commit", function()
|
||||
local _, buf = setup("alpha\nbeta\ngamma\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
blame.toggle_view(buf)
|
||||
local view_win = wait_view(buf)
|
||||
t.defer(function()
|
||||
if vim.api.nvim_win_is_valid(view_win) then
|
||||
vim.api.nvim_win_close(view_win, true)
|
||||
end
|
||||
end)
|
||||
vim.api.nvim_set_current_win(view_win)
|
||||
vim.api.nvim_win_set_cursor(view_win, { 1, 0 })
|
||||
t.press("<CR>")
|
||||
wait_buf_name("^git://%x+$")
|
||||
end)
|
||||
|
||||
t.test("closing the source window tears down the view", function()
|
||||
local _, buf = setup("alpha\nbeta\ngamma\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
local source_win = vim.api.nvim_get_current_win()
|
||||
vim.cmd("split")
|
||||
vim.api.nvim_set_current_win(source_win)
|
||||
blame.toggle_view(buf)
|
||||
local view_win = wait_view(buf)
|
||||
t.defer(function()
|
||||
if vim.api.nvim_win_is_valid(view_win) then
|
||||
vim.api.nvim_win_close(view_win, true)
|
||||
end
|
||||
end)
|
||||
vim.api.nvim_win_close(source_win, true)
|
||||
t.wait_for(function()
|
||||
return not vim.api.nvim_win_is_valid(view_win)
|
||||
end, "the view to close when the source window closes")
|
||||
end)
|
||||
|
||||
t.test("open_commit opens the commit that last touched the line", function()
|
||||
local _, buf = setup("alpha\nbeta\ngamma\n")
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
|
||||
Reference in New Issue
Block a user