From 0d6678936f83e9fbaa239a00938647ebf1501e41 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Tue, 19 Aug 2025 16:49:08 -0700 Subject: [PATCH] fix apply patch when only one file is rendered (#2468) image --- codex-rs/tui/src/chatwidget/tests.rs | 2 +- codex-rs/tui/src/diff_render.rs | 25 +++++++++++-------- ..._tui__diff_render__tests__add_details.snap | 2 +- ...er__tests__update_details_with_rename.snap | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rs index c7e9ad5b..3bb5d42f 100644 --- a/codex-rs/tui/src/chatwidget/tests.rs +++ b/codex-rs/tui/src/chatwidget/tests.rs @@ -695,7 +695,7 @@ fn apply_patch_request_shows_diff_summary() { // Per-file summary line should include the file path and counts assert!( - blob.contains("README.md (+2 -0)"), + blob.contains("README.md"), "missing per-file diff summary: {blob:?}" ); } diff --git a/codex-rs/tui/src/diff_render.rs b/codex-rs/tui/src/diff_render.rs index 24efefef..aaa7617d 100644 --- a/codex-rs/tui/src/diff_render.rs +++ b/codex-rs/tui/src/diff_render.rs @@ -130,17 +130,20 @@ pub(crate) fn create_diff_summary( for (idx, f) in files.iter().enumerate() { let mut spans: Vec> = Vec::new(); spans.push(RtSpan::raw(f.display_path.clone())); - spans.push(RtSpan::raw(" (")); - spans.push(RtSpan::styled( - format!("+{}", f.added), - Style::default().fg(Color::Green), - )); - spans.push(RtSpan::raw(" ")); - spans.push(RtSpan::styled( - format!("-{}", f.removed), - Style::default().fg(Color::Red), - )); - spans.push(RtSpan::raw(")")); + // Show per-file +/- counts only when there are multiple files + if file_count > 1 { + spans.push(RtSpan::raw(" (")); + spans.push(RtSpan::styled( + format!("+{}", f.added), + Style::default().fg(Color::Green), + )); + spans.push(RtSpan::raw(" ")); + spans.push(RtSpan::styled( + format!("-{}", f.removed), + Style::default().fg(Color::Red), + )); + spans.push(RtSpan::raw(")")); + } let mut line = RtLine::from(spans); let prefix = if idx == 0 { " └ " } else { " " }; diff --git a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__add_details.snap b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__add_details.snap index f86d2fb9..143113fb 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__add_details.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__add_details.snap @@ -3,7 +3,7 @@ source: tui/src/diff_render.rs expression: terminal.backend() --- "proposed patch to 1 file (+2 -0) " -" └ README.md (+2 -0) " +" └ README.md " " 1 +first line " " 2 +second line " " " diff --git a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__update_details_with_rename.snap b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__update_details_with_rename.snap index 76151409..9a73c0c3 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__update_details_with_rename.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__update_details_with_rename.snap @@ -4,7 +4,7 @@ assertion_line: 380 expression: terminal.backend() --- "proposed patch to 1 file (+1 -1) " -" └ src/lib.rs → src/lib_new.rs (+1 -1) " +" └ src/lib.rs → src/lib_new.rs " " 1 line one " " 2 -line two " " 2 +line two changed "