perf(util): use nvim_buf_get_offset for byte offsets in format

This commit is contained in:
2026-04-13 21:28:11 +02:00
parent fa01343730
commit 144b2ffd43
+5 -7
View File
@@ -80,13 +80,11 @@ function Util.format(opts)
)[1]
end
local function get_byte_offset(buf, row, col)
local lines = vim.api.nvim_buf_get_text(buf, 0, 0, row - 1, col - 1, {})
return #table.concat(lines, "\n")
end
local byte_start = get_byte_offset(opts.buf, row_start, col_start)
local byte_end = get_byte_offset(opts.buf, row_end, col_end) + 1
local byte_start = vim.api.nvim_buf_get_offset(opts.buf, row_start - 1)
+ col_start
- 1
local byte_end = vim.api.nvim_buf_get_offset(opts.buf, row_end - 1)
+ col_end
local input
if is_visual and opts.only_selection then