@@ -415,17 +415,35 @@ function M:update_titles()
415
415
if win .opts .title then
416
416
local tpl = win .meta .title_tpl or win .opts .title
417
417
win .meta .title_tpl = tpl
418
- local ret = {} --- @type snacks.picker.Text[]
419
- local title = Snacks .picker .util .tpl (tpl , data )
420
- if title :find (" {flags}" , 1 , true ) then
421
- title = title :gsub (" {flags}" , " " )
418
+ tpl = type (tpl ) == " string" and { { tpl , " FloatTitle" } } or tpl
419
+ --- @cast tpl - string
420
+
421
+ local has_flags = false
422
+ local is_empty = true
423
+ local ret = {}
424
+ for chunk in ipairs (tpl ) do
425
+ local text = chunk [1 ]
426
+ if text :find (" {flags}" , 1 , true ) then
427
+ text = text :gsub (" {flags}" , " " )
428
+ has_flags = true
429
+ end
430
+ text = vim .trim (Snacks .picker .util .tpl (text , data )):gsub (" %s+" , " " )
431
+ if text ~= " " then
432
+ is_empty = false
433
+ -- HACK: add extra space when last char is non word like an icon
434
+ text = text :sub (- 1 ):match (" [%w%p]" ) and text or text .. " "
435
+ end
436
+ ret [# ret + 1 ] = {
437
+ text ,
438
+ chunk [2 ],
439
+ }
440
+ end
441
+ if has_flags then
422
442
vim .list_extend (ret , toggles )
423
443
end
424
- title = vim .trim (title ):gsub (" %s+" , " " )
425
- if title ~= " " then
426
- -- HACK: add extra space when last char is non word like an icon
427
- title = title :sub (- 1 ):match (" [%w%p]" ) and title or title .. " "
428
- table.insert (ret , 1 , { " " .. title .. " " , " FloatTitle" })
444
+ if not is_empty then
445
+ table.insert (ret , 1 , { " " , " FloatTitle" })
446
+ table.insert (ret , { " " , " FloatTitle" })
429
447
end
430
448
win :set_title (ret )
431
449
end
0 commit comments