diff options
author | Wsevolod <kefirchik3@gmail.com> | 2022-06-02 10:49:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-02 09:49:57 +0200 |
commit | d5651a4183da8dfc71508850e429a7f0b99979f7 (patch) | |
tree | 3cf0da43df434b1c2d6d53564a1d3d529b052dc0 /runtime/lua/vim/highlight.lua | |
parent | 285f6518e6d4e94441742d3eb87187f1d24d122a (diff) | |
download | rneovim-d5651a4183da8dfc71508850e429a7f0b99979f7.tar.gz rneovim-d5651a4183da8dfc71508850e429a7f0b99979f7.tar.bz2 rneovim-d5651a4183da8dfc71508850e429a7f0b99979f7.zip |
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)
Diffstat (limited to 'runtime/lua/vim/highlight.lua')
-rw-r--r-- | runtime/lua/vim/highlight.lua | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 22b67aee88..36e3c2ad20 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -64,6 +64,7 @@ function M.range(bufnr, ns, higroup, start, finish, opts) end local yank_ns = api.nvim_create_namespace('hlyank') +local yank_timer --- Highlight the yanked region --- --- use from init.vim via @@ -113,6 +114,9 @@ function M.on_yank(opts) local bufnr = api.nvim_get_current_buf() api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1) + if yank_timer then + yank_timer:close() + end local pos1 = 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 } ) - vim.defer_fn(function() + yank_timer = vim.defer_fn(function() + yank_timer = nil if api.nvim_buf_is_valid(bufnr) then api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1) end |