mirror of
https://github.com/neovim/neovim
synced 2025-07-17 01:31:48 +00:00
fix(lua): stop pending highlight.on_yank timer, if any (#18824)
When yanking another range while previous yank is still highlighted, the pending timer could clear the highlight almost immediately (especially when using larger `timeout`, i.e. 2000)
This commit is contained in:
committed by
Christian Clason
parent
5243cb8a4b
commit
f15d6094fc
@ -63,7 +63,8 @@ function M.range(bufnr, ns, higroup, start, finish, opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local yank_ns = api.nvim_create_namespace("hlyank")
|
local yank_ns = api.nvim_create_namespace('hlyank')
|
||||||
|
local yank_timer
|
||||||
--- Highlight the yanked region
|
--- Highlight the yanked region
|
||||||
---
|
---
|
||||||
--- use from init.vim via
|
--- use from init.vim via
|
||||||
@ -113,6 +114,9 @@ function M.on_yank(opts)
|
|||||||
|
|
||||||
local bufnr = api.nvim_get_current_buf()
|
local bufnr = api.nvim_get_current_buf()
|
||||||
api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1)
|
api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1)
|
||||||
|
if yank_timer then
|
||||||
|
yank_timer:close()
|
||||||
|
end
|
||||||
|
|
||||||
local pos1 = vim.fn.getpos("'[")
|
local pos1 = vim.fn.getpos("'[")
|
||||||
local pos2 = vim.fn.getpos("']")
|
local pos2 = vim.fn.getpos("']")
|
||||||
@ -129,7 +133,8 @@ function M.on_yank(opts)
|
|||||||
{ regtype = event.regtype, inclusive = event.inclusive, priority = M.priorities.user }
|
{ regtype = event.regtype, inclusive = event.inclusive, priority = M.priorities.user }
|
||||||
)
|
)
|
||||||
|
|
||||||
vim.defer_fn(function()
|
yank_timer = vim.defer_fn(function()
|
||||||
|
yank_timer = nil
|
||||||
if api.nvim_buf_is_valid(bufnr) then
|
if api.nvim_buf_is_valid(bufnr) then
|
||||||
api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1)
|
api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user