feat(git): give every new git window a fresh jumplist

This commit is contained in:
2026-04-29 15:46:54 +02:00
parent 81bc011b09
commit 2335d5e0dd
5 changed files with 40 additions and 10 deletions
+25 -1
View File
@@ -34,8 +34,32 @@ local function populate(buf)
if not stdout then
return
end
local new_lines = util.split_lines(stdout)
local old_str = table.concat(
vim.api.nvim_buf_get_lines(buf, 0, -1, false),
"\n"
) .. "\n"
local new_str = table.concat(new_lines, "\n") .. "\n"
local hunks = vim.text.diff(old_str, new_str, {
result_type = "indices",
algorithm = "histogram",
})
---@cast hunks [integer, integer, integer, integer][]
if #hunks == 0 then
return
end
vim.bo[buf].modifiable = true
vim.api.nvim_buf_set_lines(buf, 0, -1, false, util.split_lines(stdout))
for i = #hunks, 1, -1 do
local sa, ca, sb, cb = unpack(hunks[i])
local start = ca == 0 and sa or sa - 1
vim.api.nvim_buf_set_lines(
buf,
start,
start + ca,
false,
vim.list_slice(new_lines, sb, sb + cb - 1)
)
end
vim.bo[buf].modifiable = false
vim.bo[buf].modified = false
end