From 144b2ffd43db6a66d9b2b02cf45ba3be1dfbe05a Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Mon, 13 Apr 2026 21:28:11 +0200 Subject: [PATCH] perf(util): use nvim_buf_get_offset for byte offsets in format --- lua/util.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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