fix(vim.hl): range(0,…) highlight not cleared after buffer-switch #40130

Problem:
When `vim.hl.range(0, …, { timeout = N })` is called, the deferred
`range_hl_clear` captures `buf=0`, which resolves to an arbitrary
"current buffer" at timeout. This may cause a stale highlight that never
gets cleared.

Solution:
Resolve `buf=0` explicitly, before `range_hl_clear` captures it.

(cherry picked from commit ec7dab077b)
This commit is contained in:
Justin M. Keyes
2026-06-06 06:26:12 -04:00
committed by github-actions[bot]
parent 3a3405d964
commit be4e7cfd6a
2 changed files with 13 additions and 4 deletions

View File

@@ -49,6 +49,8 @@ M.priorities = {
--- @return fun()? range_clear A function which allows clearing the highlight manually.
--- nil is returned if timeout is not specified
function M.range(buf, ns, higroup, start, finish, opts)
-- Resolve buf=0 so the deferred `range_hl_clear` works correctly even after buffer-switch.
buf = vim._resolve_bufnr(buf)
opts = opts or {}
local regtype = opts.regtype or 'v'
local inclusive = opts.inclusive or false