Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

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

Josh McKinneya0b2d033025b
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 0000000000..a2c3be0cf3
--- /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 6ec76a1de9..9bc9e8d664 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<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);
+ }
}