Skip to content

Commit 4a943d2

Browse files
committed
fix: fix #109, change chunk delay from 500 to 300ms
1 parent 21fb838 commit 4a943d2

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

docs/en/chunk.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ local default_conf = {
2828
error_sign = true,
2929
-- animation related
3030
duration = 200,
31-
delay = 500,
31+
delay = 300,
3232
}
3333
```
3434

@@ -60,7 +60,7 @@ The unique configuration options are `use_treesitter`, `chars`, `textobject`, `m
6060

6161
- `duration` is a number, with a default of `200` ms. It is used to control the duration of the animation.
6262

63-
- `delay` is a number, with a default of `500` ms. It is used to control the delay of the animation. If set to `0`, animation will be removed.
63+
- `delay` is a number, with a default of `300` ms. It is used to control the delay of the animation. If set to `0`, animation will be removed.
6464

6565
For the general configurations (mentioned in the [README](../../README.md)), only a few need special attention:
6666

docs/zh_CN/chunk.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ local default_conf = {
2828
error_sign = true,
2929
-- 动画相关
3030
duration = 200,
31-
delay = 500,
31+
delay = 300,
3232
}
3333
```
3434

@@ -60,7 +60,7 @@ local default_conf = {
6060

6161
- `duration` 用来控制动画的持续时间,以毫秒为单位,默认 200 ms
6262

63-
- `delay` 从移动光标到动画开始间隔的时间,以毫秒为单位,默认 500 ms,设置为 0 可以取消动画效果
63+
- `delay` 从移动光标到动画开始间隔的时间,以毫秒为单位,默认 300 ms,设置为 0 可以取消动画效果
6464

6565
对于通用的配置(在 [README](../../README.zh-CN.md) 中有提到),仅有部分需要特别注意:
6666

lua/hlchunk/mods/chunk/chunk_conf.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ local ChunkConf = class(BaseConf, function(self, conf)
3737
max_file_size = 1024 * 1024,
3838
error_sign = true,
3939
duration = 200,
40-
delay = 500,
40+
delay = 300,
4141
}
4242
conf = vim.tbl_deep_extend("force", default_conf, conf or {}) --[[@as ChunkConf]]
4343
BaseConf.init(self, conf)

lua/hlchunk/mods/chunk/init.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ end
4646
---@class ChunkMod : BaseMod
4747
---@field conf ChunkConf
4848
---@field meta ChunkMetaInfo
49-
---@field render fun(self: ChunkMod, range: Scope, opts?: {error: boolean})
49+
---@field render fun(self: ChunkMod, range: Scope, opts?: {error: boolean, lazy: boolean})
5050
---@overload fun(conf?: UserChunkConf, meta?: MetaInfo): ChunkMod
5151
local ChunkMod = class(BaseMod, constructor)
5252

@@ -120,7 +120,7 @@ function ChunkMod:get_chunk_data(range, virt_text_list, row_list, virt_text_win_
120120
end
121121

122122
function ChunkMod:render(range, opts)
123-
opts = opts or { error = false }
123+
opts = opts or { error = false, lazy = false }
124124
if not self:shouldRender(range.bufnr) then
125125
return
126126
end
@@ -131,7 +131,8 @@ function ChunkMod:render(range, opts)
131131
self:get_chunk_data(range, virt_text_list, row_list, virt_text_win_col_list)
132132

133133
if
134-
shallowCmp(virt_text_list, self.meta.pre_virt_text_list)
134+
opts.lazy
135+
and shallowCmp(virt_text_list, self.meta.pre_virt_text_list)
135136
and shallowCmp(row_list, self.meta.pre_row_list)
136137
and shallowCmp(virt_text_win_col_list, self.meta.pre_virt_text_win_col_list)
137138
and self.meta.pre_is_error == opts.error
@@ -149,7 +150,7 @@ function ChunkMod:render(range, opts)
149150
priority = 100,
150151
}
151152
local text_hl = opts.error and "HLChunk2" or "HLChunk1"
152-
if self.conf.delay == 0 then
153+
if self.conf.delay == 0 or opts.lazy == false then
153154
for i, vt in ipairs(virt_text_list) do
154155
row_opts.virt_text = { { vt, text_hl } }
155156
row_opts.virt_text_win_col = virt_text_win_col_list[i]
@@ -169,7 +170,7 @@ end
169170

170171
function ChunkMod:createAutocmd()
171172
BaseMod.createAutocmd(self)
172-
local render_cb = function(event)
173+
local render_cb = function(event, opts)
173174
local bufnr = event.buf
174175
local winid = api.nvim_get_current_win()
175176
local pos = api.nvim_win_get_cursor(winid)
@@ -183,31 +184,36 @@ function ChunkMod:createAutocmd()
183184
self.meta.leftcol = fn.winsaveview().leftcol
184185
end)
185186
if ret_code == CHUNK_RANGE_RET.OK then
186-
self:render(range, { error = false })
187+
self:render(range, { error = false, lazy = opts.lazy })
187188
elseif ret_code == CHUNK_RANGE_RET.NO_CHUNK then
188189
self:clear(Scope(bufnr, 0, api.nvim_buf_line_count(bufnr)))
189190
self:updatePreState({}, {}, {}, false)
190191
elseif ret_code == CHUNK_RANGE_RET.CHUNK_ERR then
191-
self:render(range, { error = self.conf.error_sign })
192+
self:render(range, { error = self.conf.error_sign, lazy = opts.lazy })
192193
elseif ret_code == CHUNK_RANGE_RET.NO_TS then
193194
self:notify("[hlchunk.chunk]: no parser for " .. vim.bo[bufnr].ft, nil, { once = true })
194195
end
195196
end
196197
local debounce_render_cb = debounce(render_cb, self.conf.delay)
197-
local debounce_render_cb_with_pre_hook = function(event)
198+
local debounce_render_cb_with_pre_hook = function(event, opts)
199+
opts = opts or { lazy = false }
198200
local bufnr = event.buf
199201
if not (api.nvim_buf_is_valid(bufnr) and self:shouldRender(bufnr)) then
200202
return
201203
end
202-
debounce_render_cb(event)
204+
debounce_render_cb(event, opts)
203205
end
204206
api.nvim_create_autocmd({ "CursorMovedI", "CursorMoved" }, {
205207
group = self.meta.augroup_name,
206-
callback = debounce_render_cb_with_pre_hook,
208+
callback = function(e)
209+
debounce_render_cb_with_pre_hook(e, { lazy = true })
210+
end,
207211
})
208212
api.nvim_create_autocmd({ "TextChangedI", "TextChanged" }, {
209213
group = self.meta.augroup_name,
210-
callback = debounce_render_cb_with_pre_hook,
214+
callback = function(e)
215+
debounce_render_cb_with_pre_hook(e, { lazy = false })
216+
end,
211217
})
212218
api.nvim_create_autocmd({ "UIEnter", "BufWinEnter" }, {
213219
group = self.meta.augroup_name,

0 commit comments

Comments
 (0)