aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
authorVolodymyr Chernetskyi <19735328+chernetskyi@users.noreply.github.com>2026-09-15 14:53:40 +0200
committerLewis Russell <me@lewisr.dev>2026-09-16 15:23:54 +0100
commitff039bb024ca0a8753c6591fa8cb98312090f739 (patch)
tree9c3e8eb818d49c4559e607b27056b57fa049d821 /runtime/lua
parentcb766905464dd4407465a6b880f52e156e7a01c0 (diff)
downloadrneovim-ff039bb024ca0a8753c6591fa8cb98312090f739.tar.gz
rneovim-ff039bb024ca0a8753c6591fa8cb98312090f739.tar.bz2
rneovim-ff039bb024ca0a8753c6591fa8cb98312090f739.zip
perf(hightlight): compute only bounds for non-blockwise highlights
Problem: vim.hl.range() computes a segment for every selected line, then discards all but the outer endpoints for characterwise and linewise highlights. This makes highlighting large yanks and puts unnecessarily expensive. Solution: Use getregionpos() with bounds=true for these highlights. Also use bounds in the keymap example that only needs the first and last selected lines. AI-assisted
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/vim/hl.lua8
-rw-r--r--runtime/lua/vim/keymap.lua3
2 files changed, 6 insertions, 5 deletions
diff --git a/runtime/lua/vim/hl.lua b/runtime/lua/vim/hl.lua
index 552285c7da..c02986b28e 100644
--- a/runtime/lua/vim/hl.lua
+++ b/runtime/lua/vim/hl.lua
@@ -94,15 +94,15 @@ function M.range(buf, ns, hlgroup, start, finish, opts)
end
end)
+ -- For non-blockwise selection, use a single extmark and only compute its bounds.
+ local bounds = regtype == 'v' or regtype == 'V'
local region = vim.fn.getregionpos(pos1, pos2, {
type = regtype,
exclusive = not inclusive,
eol = true,
+ bounds = bounds,
})
- -- For non-blockwise selection, use a single extmark.
- if regtype == 'v' or regtype == 'V' then
- --- @type [ [integer, integer, integer, integer], [integer, integer, integer, integer]][]
- region = { { assert(region[1])[1], assert(region[#region])[2] } }
+ if bounds then
local region1 = assert(region[1])
if
regtype == 'V'
diff --git a/runtime/lua/vim/keymap.lua b/runtime/lua/vim/keymap.lua
index 7451f42ad4..061d3340fe 100644
--- a/runtime/lua/vim/keymap.lua
+++ b/runtime/lua/vim/keymap.lua
@@ -39,9 +39,10 @@ local keymap = {}
--- type = 'v',
--- exclusive = false,
--- eol = false,
+--- bounds = true,
--- })
--- local line1 = region[1][1][2]
---- local line2 = region[#region][1][2]
+--- local line2 = region[1][2][2]
--- vim.print({ line1, line2 })
--- end)
---