Skip to content

Commit

Permalink
feat: debounce highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
AbaoFromCUG committed Apr 14, 2024
1 parent e44d794 commit c49f0e8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lua/neopyter/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,33 @@ function M.setup(opts)
if opts.enable then
local config = require("neopyter").config
local augroup = vim.api.nvim_create_augroup("neopyter-highlighter", {})
local updated = false
if opts.shortsighted then
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI", "WinScrolled" }, {
pattern = config.file_pattern,
callback = M.update_dynamic_highlight,
callback = function()
updated = false
vim.defer_fn(function()
if updated == false then
updated = true
M.update_dynamic_highlight()
end
end, 10)
end,
group = augroup,
})
else
vim.api.nvim_create_autocmd({ "BufWinEnter", "BufWritePost", "TextChanged", "TextChangedI" }, {
pattern = config.file_pattern,
callback = M.update_static_highlight,
callback = function()
updated = false
vim.defer_fn(function()
if updated == false then
updated = true
M.update_static_highlight()
end
end, 10)
end,
group = augroup,
})
end
Expand Down

0 comments on commit c49f0e8

Please sign in to comment.