From 37d4ec963b674cf33e3f43c8902f46f4bdca3e0a Mon Sep 17 00:00:00 2001 From: reidliu41 Date: Sun, 31 May 2026 12:29:27 +0800 Subject: [PATCH] fix(tui): highlight user messages in cached transcript Route user cells in the transcript cache through the existing user-message renderer. The live chat view renders through lines_with_copy_metadata(), which previously bypassed the user-message highlight path. As a result, submitted user prompts did not show the intended full-row background in the main transcript. Add a regression test for the transcript cache path. --- crates/tui/src/tui/history.rs | 10 +++------- crates/tui/src/tui/transcript.rs | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/crates/tui/src/tui/history.rs b/crates/tui/src/tui/history.rs index f2ce686e..1c329ac8 100644 --- a/crates/tui/src/tui/history.rs +++ b/crates/tui/src/tui/history.rs @@ -309,13 +309,9 @@ impl HistoryCell { options: TranscriptRenderOptions, ) -> Vec { match self { - HistoryCell::User { content } => render_message_with_copy_metadata( - USER_GLYPH, - user_label_style(), - user_body_style(), - content, - width, - ), + HistoryCell::User { content } => { + hard_break_copy_lines(render_user_message(content, width)) + } HistoryCell::Assistant { content, streaming } => render_message_with_copy_metadata( ASSISTANT_GLYPH, assistant_label_style_for(*streaming, options.low_motion), diff --git a/crates/tui/src/tui/transcript.rs b/crates/tui/src/tui/transcript.rs index 53319c96..64d12bea 100644 --- a/crates/tui/src/tui/transcript.rs +++ b/crates/tui/src/tui/transcript.rs @@ -554,6 +554,7 @@ fn truncate_spans_to_width(spans: Vec>, max_width: usize) -> Vec Vec { @@ -595,6 +596,20 @@ mod tests { })) } + #[test] + fn cache_renders_user_cells_with_highlight_background() { + let cells = vec![user_cell("# literal user prompt")]; + let revisions = vec![1u64]; + + let mut cache = TranscriptViewCache::new(); + cache.ensure(&cells, &revisions, 40, TranscriptRenderOptions::default()); + + let lines = cache.lines(); + assert_eq!(lines[0].style.bg, Some(palette::SURFACE_ELEVATED)); + assert_eq!(lines[0].width(), 40); + assert_eq!(plain_lines(&cache)[0].trim_end(), "▎ # literal user prompt"); + } + #[test] fn cache_reuses_cells_when_revision_unchanged() { let cells = vec![