@@ -184,6 +184,7 @@ local function close_stack_item(stack, idx, item)
184184 local history_entry = {
185185 location = item .location ,
186186 title = item .title ,
187+ title_chunks = item .title_chunks ,
187188 pinned = item .pinned ,
188189 buffer_mode = item .buffer_mode or " copy" ,
189190 source_bufnr = item .source_bufnr ,
@@ -265,10 +266,15 @@ end
265266local function restore_entry (stack , entry )
266267 deps ()
267268 local create_opts = {
268- title = entry .title ,
269269 buffer_mode = entry .buffer_mode or " copy" ,
270270 origin_winid = stack .root_winid ,
271271 }
272+ -- Only pass title override for user-renamed popups (no title_chunks).
273+ -- Auto-generated titles are regenerated by build_title() to preserve
274+ -- structured chunks for popup window and stack view highlighting.
275+ if not entry .title_chunks then
276+ create_opts .title = entry .title
277+ end
272278
273279 -- For source mode, check if the source buffer is still valid
274280 if create_opts .buffer_mode == " source" and entry .source_bufnr then
@@ -448,11 +454,14 @@ function M.reopen_by_id(id, winid)
448454 local stack = ensure_stack (winid )
449455 for idx , item in ipairs (stack .popups ) do
450456 if item .id == id then
451- local model = popup .create (item .location , {
452- title = item .title ,
457+ local reopen_opts = {
453458 buffer_mode = item .buffer_mode or " copy" ,
454459 origin_winid = stack .root_winid ,
455- })
460+ }
461+ if not item .title_chunks then
462+ reopen_opts .title = item .title
463+ end
464+ local model = popup .create (item .location , reopen_opts )
456465 if not model then
457466 return nil
458467 end
@@ -522,6 +531,7 @@ function M.handle_win_closed(winid)
522531 local history_entry = {
523532 location = item .location ,
524533 title = item .title ,
534+ title_chunks = item .title_chunks ,
525535 pinned = item .pinned ,
526536 buffer_mode = item .buffer_mode or " copy" ,
527537 source_bufnr = item .source_bufnr ,
@@ -566,6 +576,7 @@ function M.rename_by_id(id, title, winid)
566576 for _ , item in ipairs (stack .popups ) do
567577 if item .id == id then
568578 item .title = title
579+ item .title_chunks = nil
569580 return true
570581 end
571582 end
@@ -774,6 +785,7 @@ function M.close_all(winid)
774785 local history_entry = {
775786 location = item .location ,
776787 title = item .title ,
788+ title_chunks = item .title_chunks ,
777789 pinned = item .pinned ,
778790 buffer_mode = item .buffer_mode or " copy" ,
779791 source_bufnr = item .source_bufnr ,
0 commit comments