Skip to content

Commit d1caa1c

Browse files
committed
fix(diagnostic): correct mode change handling in autocmd
1 parent 66d9166 commit d1caa1c

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

lua/tiny-inline-diagnostic/diagnostic.lua

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,24 @@ end
199199
local function setup_mode_change_autocmds(autocmd_ns, event)
200200
vim.api.nvim_create_autocmd("ModeChanged", {
201201
group = autocmd_ns,
202-
pattern = { "*:[vV\x16is]*" },
203202
callback = function()
204-
if vim.api.nvim_buf_is_valid(event.buf) then
205-
disable()
206-
extmarks.clear(event.buf)
207-
else
208-
detach_buffer(event.buf)
209-
end
210-
end,
211-
})
203+
local mode = vim.api.nvim_get_mode().mode
204+
205+
local disabled_mode = {
206+
"i",
207+
"v",
208+
"V",
209+
"",
210+
}
212211

213-
vim.api.nvim_create_autocmd("ModeChanged", {
214-
group = autocmd_ns,
215-
pattern = "[vV\x16i]*:*",
216-
callback = function()
217212
if vim.api.nvim_buf_is_valid(event.buf) then
218-
enable()
213+
if vim.tbl_contains(disabled_mode, mode) then
214+
disable()
215+
else
216+
enable()
217+
end
218+
219+
extmarks.clear(event.buf)
219220
else
220221
detach_buffer(event.buf)
221222
end

0 commit comments

Comments
 (0)