fix(lua): verify buffer in highlight.on_yank (#15482)

Resolve an issue with deferred clearing of highlight failing if the 
buffer is deleted before the timeout by checking whether the
buffer is valid first.
This commit is contained in:
notomo
2021-08-26 23:37:36 +09:00
committed by GitHub
parent 6ff1e3fa1f
commit 274a3504a7
2 changed files with 31 additions and 1 deletions

View File

@@ -85,7 +85,11 @@ function highlight.on_yank(opts)
highlight.range(bufnr, yank_ns, higroup, pos1, pos2, event.regtype, event.inclusive)
vim.defer_fn(
function() api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1) end,
function()
if api.nvim_buf_is_valid(bufnr) then
api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1)
end
end,
timeout
)
end