From a0b2d033025b704963ebcef2ebd2fdbeee34b731 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Tue, 6 Jan 2026 11:21:26 -0800 Subject: [PATCH] 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) --- ...i__tests__copy_pill_clears_background.snap | 7 ++++++ codex-rs/tui2/src/transcript_copy_ui.rs | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 codex-rs/tui2/src/snapshots/codex_tui2__transcript_copy_ui__tests__copy_pill_clears_background.snap diff --git a/codex-rs/tui2/src/snapshots/codex_tui2__transcript_copy_ui__tests__copy_pill_clears_background.snap b/codex-rs/tui2/src/snapshots/codex_tui2__transcript_copy_ui__tests__copy_pill_clears_background.snap new file mode 100644 index 000000000..a2c3be0cf --- /dev/null +++ b/codex-rs/tui2/src/snapshots/codex_tui2__transcript_copy_ui__tests__copy_pill_clears_background.snap @@ -0,0 +1,7 @@ +--- +source: tui2/src/transcript_copy_ui.rs +expression: rendered +--- +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxx ⧉ copy ctrl + shift + c xxxxx diff --git a/codex-rs/tui2/src/transcript_copy_ui.rs b/codex-rs/tui2/src/transcript_copy_ui.rs index 6ec76a1de..9bc9e8d66 100644 --- a/codex-rs/tui2/src/transcript_copy_ui.rs +++ b/codex-rs/tui2/src/transcript_copy_ui.rs @@ -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> = 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); + } }