@@ -14,16 +14,19 @@ M.last_draw_time = 0
1414--- @field first integer 0 indexed , inclusive
1515--- @field last integer Exclusive
1616
17- --- @class renderer.HlList : { [ integer ] : renderer.HlData }
17+ --- @class renderer.HlList
1818--- @field offset integer
19+ --- @field [ integer] renderer.HlData
1920
20- --- @class CompStruct : { [ integer | string ] : CompStruct }
21+ --- @class CompStruct
2122--- @field _name string
2223--- @field comp RenderComponent
24+ --- @field [ integer | string] CompStruct
2325
24- --- @class CompSchema : { [ integer ] : CompSchema }
26+ --- @class CompSchema
2527--- @field name ? string
2628--- @field context ? table
29+ --- @field [ integer] CompSchema
2730
2831--- @class RenderComponent : diffview.Object
2932--- @field name string
@@ -36,7 +39,6 @@ M.last_draw_time = 0
3639--- @field lstart integer 0 indexed , Inclusive
3740--- @field lend integer Exclusive
3841--- @field height integer
39- --- @field leaf boolean
4042--- @field data_root RenderData
4143local RenderComponent = oop .create_class (" RenderComponent" )
4244
@@ -50,7 +52,6 @@ function RenderComponent:init(name)
5052 self .lstart = - 1
5153 self .lend = - 1
5254 self .height = 0
53- self .leaf = false
5455end
5556
5657--- @param parent RenderComponent
@@ -71,8 +72,6 @@ local function create_subcomponents(parent, comp_struct, schema)
7172 comp_struct [v .name ] = comp_struct [i ]
7273 if # v > 0 then
7374 create_subcomponents (sub_comp , comp_struct [i ], v )
74- else
75- sub_comp .leaf = true
7675 end
7776 end
7877end
@@ -199,28 +198,24 @@ function RenderComponent:destroy()
199198 self .components = nil
200199end
201200
201+ function RenderComponent :isleaf ()
202+ return (not next (self .components ))
203+ end
204+
202205--- @param line integer
203206--- @return RenderComponent ?
204207function RenderComponent :get_comp_on_line (line )
205208 line = line - 1
209+ local ret
206210
207- local function recurse (child )
208- if line >= child .lstart and line < child .lend then
209- -- print(child.name, line, child.lstart, child.lend)
210- if # child .components > 0 then
211- for _ , v in ipairs (child .components ) do
212- local target = recurse (v )
213- if target then
214- return target
215- end
216- end
217- else
218- return child
219- end
211+ self :deep_some (function (child )
212+ if line >= child .lstart and line < child .lend and child :isleaf () then
213+ ret = child
214+ return true
220215 end
221- end
216+ end )
222217
223- return recurse ( self )
218+ return ret
224219end
225220
226221--- @param callback fun ( comp : RenderComponent , i : integer , parent : RenderComponent ): boolean ?
0 commit comments