-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51ffe50
commit 797f1b0
Showing
6 changed files
with
58 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
local M = {} | ||
|
||
-- Table to store timers for each debounced function | ||
local timers = {} | ||
|
||
-- Debounce function | ||
-- @param func The function to debounce | ||
-- @param delay The delay in milliseconds | ||
-- @return The debounced function | ||
function M.debounce(func, delay) | ||
return function(...) | ||
local args = { ... } | ||
local key = tostring(func) | ||
|
||
if timers[key] then | ||
vim.loop.timer_stop(timers[key]) | ||
end | ||
|
||
timers[key] = vim.loop.new_timer() | ||
timers[key]:start( | ||
delay, | ||
0, | ||
vim.schedule_wrap(function() | ||
func(unpack(args)) | ||
timers[key]:close() | ||
timers[key] = nil | ||
end) | ||
) | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters