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.
This commit is contained in:
reidliu41
2026-05-31 12:29:27 +08:00
committed by Hunter Bown
parent 7c8df7a6da
commit 37d4ec963b
2 changed files with 18 additions and 7 deletions
+3 -7
View File
@@ -309,13 +309,9 @@ impl HistoryCell {
options: TranscriptRenderOptions,
) -> Vec<RenderedTranscriptLine> {
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),
+15
View File
@@ -554,6 +554,7 @@ fn truncate_spans_to_width(spans: Vec<Span<'static>>, max_width: usize) -> Vec<S
#[cfg(test)]
mod tests {
use super::*;
use crate::palette;
use crate::tui::history::{ExecCell, ExecSource, HistoryCell, ToolCell, ToolStatus};
fn plain_lines(cache: &TranscriptViewCache) -> Vec<String> {
@@ -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![