@@ -12,7 +12,6 @@ local fn = vim.fn
1212local ROWS_INDENT_RETCODE = indentHelper .ROWS_INDENT_RETCODE
1313
1414--- @class HlChunk.IndentMetaInfo : HlChunk.MetaInfo
15- --- @field pre_leftcol number
1615
1716local constructor = function (self , conf , meta )
1817 local default_meta = {
@@ -21,7 +20,6 @@ local constructor = function(self, conf, meta)
2120 hl_base_name = " HLIndent" ,
2221 ns_id = api .nvim_create_namespace (" indent" ),
2322 shiftwidth = fn .shiftwidth (),
24- pre_leftcol = 0 ,
2523 leftcol = fn .winsaveview ().leftcol ,
2624 }
2725
@@ -157,8 +155,21 @@ function IndentMod:render(range, opts)
157155 self :setmark (bufnr , render_info )
158156end
159157
160- function IndentMod :createRenderCallback ()
158+ function IndentMod :createThrottledCallback (callback )
159+ local throttledCallback = throttle (callback , self .conf .delay )
161160 return function (event , opts )
161+ opts = opts or { lazy = false }
162+ local bufnr = event .buf
163+ if not (api .nvim_buf_is_valid (bufnr ) and self :shouldRender (bufnr )) then
164+ return
165+ end
166+ throttledCallback (event , opts )
167+ end
168+ end
169+
170+ function IndentMod :createAutocmd ()
171+ BaseMod .createAutocmd (self )
172+ local throttledCallback = self :createThrottledCallback (function (event , opts )
162173 opts = opts or { lazy = false }
163174 local bufnr = event .buf
164175 if not self :shouldRender (bufnr ) then
@@ -167,45 +178,23 @@ function IndentMod:createRenderCallback()
167178
168179 local wins = fn .win_findbuf (bufnr ) or {}
169180 for _ , winid in ipairs (wins ) do
170- local win_bufnr = api .nvim_win_get_buf (winid )
171- local range = Scope (win_bufnr , fn .line (" w0" , winid ) - 1 , fn .line (" w$" , winid ) - 1 )
181+ local range = Scope (bufnr , fn .line (" w0" , winid ) - 1 , fn .line (" w$" , winid ) - 1 )
172182 local ahead_lines = self .conf .ahead_lines
173183 range .start = math.max (0 , range .start - ahead_lines )
174- range .finish = math.min (api .nvim_buf_line_count (win_bufnr ) - 1 , range .finish + ahead_lines )
184+ range .finish = math.min (api .nvim_buf_line_count (bufnr ) - 1 , range .finish + ahead_lines )
175185 api .nvim_win_call (winid , function ()
176- self .meta .shiftwidth = cFunc .get_sw (win_bufnr )
177- self .meta .pre_leftcol = self .meta .leftcol
186+ self .meta .shiftwidth = cFunc .get_sw (bufnr )
178187 self .meta .leftcol = fn .winsaveview ().leftcol
179- if self .meta .pre_leftcol ~= self .meta .leftcol then
180- opts .lazy = false
181- end
182188 self :render (range , opts )
183189 end )
184190 end
185- end
186- end
187-
188- function IndentMod :createThrottledCallback (callback )
189- local throttledCallback = throttle (callback , self .conf .delay )
190- return function (event , opts )
191- opts = opts or { lazy = false }
192- local bufnr = event .buf
193- if not (api .nvim_buf_is_valid (bufnr ) and self :shouldRender (bufnr )) then
194- return
195- end
196- throttledCallback (event , opts )
197- end
198- end
199-
200- function IndentMod :createAutocmd ()
201- BaseMod .createAutocmd (self )
202- local renderCallback = self :createRenderCallback ()
203- local throttledCallback = self :createThrottledCallback (renderCallback )
191+ end )
204192
205193 local autocommands = {
206- { events = { " WinScrolled" }, opts = { lazy = true } },
194+ { events = { " User" }, pattern = " WinScrolledX" , opts = { lazy = false } },
195+ { events = { " User" }, pattern = " WinScrolledY" , opts = { lazy = true } },
207196 { events = { " TextChanged" , " TextChangedI" , " BufWinEnter" }, opts = { lazy = false } },
208- { events = { " OptionSet" }, pattern = " list,listchars, shiftwidth,tabstop,expandtab" , opts = {} },
197+ { events = { " OptionSet" }, pattern = " list,shiftwidth,tabstop,expandtab" , opts = { lazy = false } },
209198 }
210199
211200 for _ , cmd in ipairs (autocommands ) do
0 commit comments