From 523047fac696ab2acdbfd6fec707587c64d6f9d7 Mon Sep 17 00:00:00 2001 From: gbprod Date: Mon, 9 Oct 2023 09:34:24 +0200 Subject: [PATCH] fix(range): always apply matchadd Fixes: #70 --- lua/substitute/range.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lua/substitute/range.lua b/lua/substitute/range.lua index cee5de9..a156f17 100644 --- a/lua/substitute/range.lua +++ b/lua/substitute/range.lua @@ -21,12 +21,14 @@ local function create_match(c) range.clear_match() range.state.match = vim.fn.matchadd("SubstituteRange", get_escaped_subject(c), 2) - range.state.augroup = vim.api.nvim_create_augroup("SubstituteClearMatch", { clear = true }) - vim.api.nvim_create_autocmd({ "InsertEnter", "WinLeave", "BufLeave", "CursorMoved" }, { - group = range.state.augroup, - pattern = "*", - callback = range.clear_match, - }) + vim.schedule_wrap(function() + range.state.augroup = vim.api.nvim_create_augroup("SubstituteClearMatch", { clear = true }) + vim.api.nvim_create_autocmd({ "InsertEnter", "WinLeave", "BufLeave", "CursorMoved" }, { + group = range.state.augroup, + pattern = "*", + callback = range.clear_match, + }) + end) end function range.operator(options)