@@ -3,6 +3,7 @@ local IndentConf = require("hlchunk.mods.indent.indent_conf")
33local class = require (" hlchunk.utils.class" )
44local indentHelper = require (" hlchunk.utils.indentHelper" )
55local Scope = require (" hlchunk.utils.scope" )
6+ local Cache = require (" hlchunk.utils.cache" )
67local throttle = require (" hlchunk.utils.timer" ).throttle
78local cFunc = require (" hlchunk.utils.cFunc" )
89
@@ -11,7 +12,7 @@ local fn = vim.fn
1112local ROWS_INDENT_RETCODE = indentHelper .ROWS_INDENT_RETCODE
1213
1314--- @class IndentMetaInfo : MetaInfo
14- --- @field cache table<number , number>
15+ --- @field cache Cache
1516
1617local constructor = function (self , conf , meta )
1718 local default_meta = {
@@ -21,7 +22,7 @@ local constructor = function(self, conf, meta)
2122 ns_id = api .nvim_create_namespace (" indent" ),
2223 shiftwidth = fn .shiftwidth (),
2324 leftcol = fn .winsaveview ().leftcol ,
24- cache = {} ,
25+ cache = Cache () ,
2526 }
2627
2728 BaseMod .init (self , conf , meta )
@@ -62,13 +63,13 @@ function IndentMod:render(range)
6263 local non_cached_start = range .start
6364 local non_cached_finish = range .finish
6465 for i = range .start , range .finish do
65- if not self .meta .cache [ i ] then
66+ if not self .meta .cache : has ( range . bufnr , i ) then
6667 non_cached_start = i
6768 break
6869 end
6970 end
7071 for i = non_cached_start , range .finish do
71- if self .meta .cache [ i ] then
72+ if self .meta .cache : has ( range . bufnr , i ) then
7273 non_cached_finish = i - 1
7374 break
7475 end
@@ -85,10 +86,10 @@ function IndentMod:render(range)
8586 return
8687 end
8788 for lnum , indent in pairs (rows_indent ) do
88- self .meta .cache [ lnum ] = indent
89+ self .meta .cache : set ( range . bufnr , lnum , indent )
8990 end
9091 for lnum = range .start , range .finish do
91- self :renderLine (range .bufnr , lnum , self .meta .cache [ lnum ] )
92+ self :renderLine (range .bufnr , lnum , self .meta .cache : get ( range . bufnr , lnum ) )
9293 end
9394end
9495
@@ -128,7 +129,7 @@ function IndentMod:createAutocmd()
128129 api .nvim_create_autocmd ({ " TextChanged" , " TextChangedI" }, {
129130 group = self .meta .augroup_name ,
130131 callback = function (e )
131- self .meta .cache = {}
132+ self .meta .cache : clear ( e . buf )
132133 throttle_render_cb_with_pre_hook (e )
133134 end ,
134135 })
0 commit comments