Clear copy pill background and add snapshot test (#8777)

### Motivation
- Fix a visual bug where transcript text could bleed through the
on-screen copy "pill" overlay.
- Ensure the copy affordance fully covers the underlying buffer so the
pill background is solid and consistent with styling.
- Document the approach in-code to make the background-clearing
rationale explicit.

### Description
- Clear the pill area before drawing by iterating `Rect::positions()`
and calling `cell.set_symbol(" ")` and `cell.set_style(base_style)` in
`render_copy_pill` in `transcript_copy_ui.rs`.
- Added an explanatory comment for why the pill background is explicitly
cleared.
- Added a unit test `copy_pill_clears_background` and committed the
corresponding snapshot file to validate the rendering behavior.

### Testing
- Ran `just fmt` (formatting completed; non-blocking environment warning
may appear).
- Ran `just fix -p codex-tui2` to apply lints/fixes (completed). 
- Ran `cargo test -p codex-tui2` and all tests passed (snapshot updated
and tests succeeded).

------
[Codex
Task](https://chatgpt.com/codex/tasks/task_i_695c9b23e9b8832997d5a457c4d83410)
This commit is contained in:
Josh McKinney 2026-01-06 11:21:26 -08:00 committed by GitHub
parent 4ce9d0aa7b
commit a0b2d03302
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,7 @@
---
source: tui2/src/transcript_copy_ui.rs
expression: rendered
---
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxx ⧉ copy ctrl + shift + c xxxxx

View file

@ -287,6 +287,13 @@ impl TranscriptCopyUi {
let icon_style = base_style.add_modifier(Modifier::BOLD).fg(Color::LightCyan);
let bold_style = base_style.add_modifier(Modifier::BOLD);
// Clear background so underlying text doesn't bleed through the pill.
for position in pill_area.positions() {
let cell = &mut buf[position];
cell.set_symbol(" ");
cell.set_style(base_style);
}
let mut spans: Vec<Span<'static>> = vec![
Span::styled(" ", base_style),
Span::styled("", icon_style),
@ -305,6 +312,7 @@ impl TranscriptCopyUi {
#[cfg(test)]
mod tests {
use super::*;
use insta::assert_snapshot;
use ratatui::buffer::Buffer;
fn buf_to_string(buf: &Buffer, area: Rect) -> String {
@ -359,4 +367,21 @@ mod tests {
assert_eq!(rect.y, 1);
assert!(ui.hit_test(rect.x, rect.y));
}
#[test]
fn copy_pill_clears_background() {
let area = Rect::new(0, 0, 40, 3);
let mut buf = Buffer::empty(area);
for y in 0..area.height {
for x in 0..area.width {
buf[(x, y)].set_symbol("x");
}
}
let mut ui = TranscriptCopyUi::new_with_shortcut(CopySelectionShortcut::CtrlShiftC);
ui.render_copy_pill(area, &mut buf, (1, 2), (1, 6), 0, 3);
let rendered = buf_to_string(&buf, area);
assert_snapshot!("copy_pill_clears_background", rendered);
}
}