From 1c28f99b81f3b0b627686ceb882293a9b23556e5 Mon Sep 17 00:00:00 2001 From: Fei Shao Date: Tue, 5 May 2026 23:28:15 +0800 Subject: [PATCH] fix(buffer): wrap non-virtualtext nvim_buf_set_extmark in pcall When scrolling or editing rapidly, asynchronous updates or byte-offset calculation misalignments (e.g. in files with control characters like '^[[1;31m' or multi-byte sequences) can attempt to apply highlights to invalid column ranges. This causes Neovim to throw an "Invalid 'end_col': out of range" error in function nvim_buf_set_extmark(). Wrap the non-virtualtext highlight application in a pcall to safely ignore stale or invalid column offsets. This provides the same protection already present in the virtualtext highlighting logic in the same function. --- lua/colorizer/buffer.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/colorizer/buffer.lua b/lua/colorizer/buffer.lua index a249a7a..b0a2f19 100644 --- a/lua/colorizer/buffer.lua +++ b/lua/colorizer/buffer.lua @@ -220,11 +220,13 @@ function M.add_highlight(bufnr, ns_id, line_start, line_end, data, opts, hl_opts -- Non-virtualtext: one extmark with combined highlight group if #non_vt_modes > 0 then local hlname = create_combined_highlight(hl.rgb_hex, non_vt_modes, bg_opts) - vim.api.nvim_buf_set_extmark(bufnr, ns_id, linenr, hl.range[1], { - end_col = hl.range[2], - hl_group = hlname, - priority = priority, - }) + pcall(function() + vim.api.nvim_buf_set_extmark(bufnr, ns_id, linenr, hl.range[1], { + end_col = hl.range[2], + hl_group = hlname, + priority = priority, + }) + end) end -- Virtualtext: separate extmark