Skip to content

Commit 3a9ce3a

Browse files
committed
fix: update debounce function, add fzf ft ignore
1 parent 9f5dd1b commit 3a9ce3a

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

lua/hlchunk/mods/chunk/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local ChunkConf = require("hlchunk.mods.chunk.chunk_conf")
33
local chunkHelper = require("hlchunk.utils.chunkHelper")
44
local LoopTask = require("hlchunk.utils.loopTask")
55
local debounce = require("hlchunk.utils.timer").debounce
6+
local debounce_throttle = require("hlchunk.utils.timer").debounce_throttle
67
local Pos = require("hlchunk.utils.position")
78
local Scope = require("hlchunk.utils.scope")
89
local cFunc = require("hlchunk.utils.cFunc")
@@ -202,7 +203,7 @@ function ChunkMod:createAutocmd()
202203
end
203204
end
204205
local db_render_cb = debounce(render_cb, self.conf.delay, false)
205-
local db_render_cb_imm = debounce(render_cb, self.conf.delay, true)
206+
local db_render_cb_imm = debounce_throttle(render_cb, self.conf.delay)
206207
local db_render_cb_with_pre_hook = function(event, opts)
207208
opts = opts or { lazy = false }
208209
local bufnr = event.buf

lua/hlchunk/utils/filetype.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ M.exclude_filetypes = {
1212
mason = true,
1313
NvimTree = true,
1414
["neo-tree"] = true,
15+
["neo-tree-popup"] = true,
1516
plugin = true,
1617
lazy = true,
1718
TelescopePrompt = true,
@@ -48,6 +49,7 @@ M.exclude_filetypes = {
4849
startify = true,
4950
oil = true,
5051
glowpreview = true,
52+
fzf = true,
5153
}
5254

5355
return M

lua/hlchunk/utils/timer.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,30 @@ function M.debounce(fn, delay, first)
6666
end
6767
end
6868

69+
function M.debounce_throttle(fn, delay)
70+
local timer = nil
71+
local called = false
72+
73+
return function(...)
74+
local args = { ... }
75+
if timer then
76+
timer:stop()
77+
end
78+
79+
if not called then
80+
fn(unpack(args))
81+
called = true
82+
M.setTimeout(function()
83+
called = false
84+
end, delay)
85+
else
86+
timer = M.setTimeout(function()
87+
fn(unpack(args))
88+
end, delay)
89+
end
90+
end
91+
end
92+
6993
---throttle function, assume we call a throttled func every 300ms for 9 times, and interval set to 1000ms
7094
---then will actually call 3 times, and timeline as follow:
7195
---`0ms` 300ms 600ms 900ms call throttled func, 0ms will tigger the timer, other 3 will be ignored

0 commit comments

Comments
 (0)