perf(util): use nvim_buf_get_offset for byte offsets in format
This commit is contained in:
+5
-7
@@ -80,13 +80,11 @@ function Util.format(opts)
|
|||||||
)[1]
|
)[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_byte_offset(buf, row, col)
|
local byte_start = vim.api.nvim_buf_get_offset(opts.buf, row_start - 1)
|
||||||
local lines = vim.api.nvim_buf_get_text(buf, 0, 0, row - 1, col - 1, {})
|
+ col_start
|
||||||
return #table.concat(lines, "\n")
|
- 1
|
||||||
end
|
local byte_end = vim.api.nvim_buf_get_offset(opts.buf, row_end - 1)
|
||||||
|
+ col_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 input
|
local input
|
||||||
if is_visual and opts.only_selection then
|
if is_visual and opts.only_selection then
|
||||||
|
|||||||
Reference in New Issue
Block a user