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]
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user