feat(git): give every new git window a fresh jumplist
This commit is contained in:
+25
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user