refactor(git): generalize buf_set_lines wrapper

This commit is contained in:
2026-05-06 15:43:03 +02:00
parent f53ac540b3
commit 6fdd455536
5 changed files with 10 additions and 9 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ local function run_in_split(r, args, conf)
end
end
vim.bo[buf].filetype = conf.ft
util.replace_buf_lines(buf, util.split_lines(stdout))
util.buf_set_lines(buf, 0, -1, false, util.split_lines(stdout))
end,
})
end
+2 -4
View File
@@ -73,11 +73,10 @@ local function populate(buf, r)
if #hunks == 0 then
return
end
vim.bo[buf].modifiable = true
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(
util.buf_set_lines(
buf,
start,
start + ca,
@@ -85,8 +84,6 @@ local function populate(buf, r)
vim.list_slice(new_lines, sb, sb + cb - 1)
)
end
vim.bo[buf].modifiable = false
vim.bo[buf].modified = false
end
---@param buf integer
@@ -105,6 +102,7 @@ function M.read_uri(buf)
vim.bo[buf].swapfile = false
vim.bo[buf].bufhidden = "hide"
vim.bo[buf].buftype = "nofile"
vim.bo[buf].modifiable = false
if vim.bo[buf].filetype ~= "gitlog" then
vim.bo[buf].filetype = "gitlog"
end
+1 -1
View File
@@ -199,7 +199,7 @@ local function populate(buf, r, rev, state, rev_sha)
end
end
util.replace_buf_lines(buf, util.split_lines(stdout))
util.buf_set_lines(buf, 0, -1, false, util.split_lines(stdout))
state.sha = rev_sha
return true
end
+1 -1
View File
@@ -132,7 +132,7 @@ local function render(bufnr, status)
end
end
util.replace_buf_lines(bufnr, lines)
util.buf_set_lines(bufnr, 0, -1, false, lines)
vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
for _, m in ipairs(marks) do
vim.api.nvim_buf_set_extmark(bufnr, ns, m.row, m.col, {
+5 -2
View File
@@ -81,11 +81,14 @@ function M.debug(fmt, ...)
end
---@param buf integer
---@param start integer
---@param end_ integer
---@param strict_indexing boolean
---@param lines string[]
function M.replace_buf_lines(buf, lines)
function M.buf_set_lines(buf, start, end_, strict_indexing, lines)
local was_modifiable = vim.bo[buf].modifiable
vim.bo[buf].modifiable = true
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
vim.api.nvim_buf_set_lines(buf, start, end_, strict_indexing, lines)
vim.bo[buf].modifiable = was_modifiable
vim.bo[buf].modified = false
end