@@ -42,7 +42,7 @@ local log = require 'lean.log'
4242--- @field events EventCallbacks functions to fire for events which this element responds to
4343--- @field text string the text to show when rendering this element
4444--- @field name string a named handle for this element , used when path-searching
45- --- @field hlgroup ? string | fun ( string ): string ? the highlight group for this element ' s text, or a function that returns it
45+ --- @field hlgroups ? string[] | fun (): string[] | nil the highlight group( s ) for this element ' s text, or a function that returns them
4646--- @field tooltip ? Element ? tooltip
4747--- @field highlightable boolean (for buffer rendering ) whether to highlight this element when hovering over it
4848--- @field _size ? integer Computed size of this element , updated by ` Element:to_string`
@@ -73,7 +73,7 @@ BufRenderer.__index = BufRenderer
7373--- @field events ? EventCallbacks event function map
7474--- @field text ? string the text to show when rendering this element
7575--- @field name ? string a named handle for this element , used when path-searching
76- --- @field hlgroup ? string | fun (): string ? the highlight group for this element ' s text, or a function that returns it
76+ --- @field hlgroups ? string[] | fun (): string[] | nil the highlight group( s ) for this element ' s text, or a function that returns them
7777--- @field highlightable boolean ? (for buffer rendering ) whether to highlight this element when hovering over it
7878--- @field children ? Element[] this element ' s children
7979--- @field private __async_init ? fun ( on_result : fun ( Element ): nil ): nil
@@ -86,7 +86,7 @@ function Element:new(args)
8686 local obj = {
8787 text = args .text or ' ' ,
8888 name = args .name or ' ' ,
89- hlgroup = args .hlgroup ,
89+ hlgroups = args .hlgroups ,
9090 highlightable = args .highlightable or false ,
9191 events = args .events or {},
9292 __children = args .children or {},
@@ -114,7 +114,7 @@ function Element:titled(opts)
114114 return body
115115 end
116116
117- local title = self :new { text = opts .title , hlgroup = opts .title_hlgroup }
117+ local title = self :new { text = opts .title , hlgroups = opts .title_hlgroup and { opts . title_hlgroup } or nil }
118118
119119 if not body then
120120 return title
@@ -189,7 +189,7 @@ function Element.select(choices, opts, on_choice)
189189 Element :new { text = ' ▾' },
190190 },
191191 highlightable = true ,
192- hlgroup = ' widgetSelect' ,
192+ hlgroups = { ' widgetSelect' } ,
193193 events = {
194194 click = function (ctx )
195195 vim .ui .select (choices , {
214214--- @param key string
215215--- @return Element
216216function Element .kbd (key )
217- return Element :new { text = key , hlgroup = ' widgetKbd' }
217+ return Element :new { text = key , hlgroups = { ' widgetKbd' } }
218218end
219219
220220--- Create an Element whose click event does nothing.
@@ -308,16 +308,18 @@ function Element:_get_highlights()
308308 --- @param element Element
309309 --- @param pos integer
310310 local function go (element , pos )
311- local hlgroup = element .hlgroup
312- if type (hlgroup ) == ' function' then
313- hlgroup = hlgroup (element )
311+ local hlgroups = element .hlgroups
312+ if type (hlgroups ) == ' function' then
313+ hlgroups = hlgroups (element )
314314 end
315- if hlgroup then
316- table.insert (hls , {
317- start = pos ,
318- [' end' ] = pos + element ._size ,
319- hlgroup = hlgroup ,
320- })
315+ if hlgroups then
316+ for _ , hg in ipairs (hlgroups ) do
317+ table.insert (hls , {
318+ start = pos ,
319+ [' end' ] = pos + element ._size ,
320+ hlgroup = hg ,
321+ })
322+ end
321323 end
322324
323325 pos = pos + # element .text
0 commit comments