diff --git a/lua/util.lua b/lua/util.lua index f103d40..7513b5b 100644 --- a/lua/util.lua +++ b/lua/util.lua @@ -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