diff --git a/codex-rs/tui/src/diff_render.rs b/codex-rs/tui/src/diff_render.rs index 9df58fb7e66f..9972a3fa635d 100644 --- a/codex-rs/tui/src/diff_render.rs +++ b/codex-rs/tui/src/diff_render.rs @@ -48,8 +48,10 @@ use std::path::PathBuf; use codex_utils_absolute_path::AbsolutePathBuf; use unicode_width::UnicodeWidthChar; +/// Replacement for a tab character in rendered diff content. +const TAB_REPLACEMENT: &str = " "; /// Display width of a tab character in columns. -const TAB_WIDTH: usize = 4; +const TAB_WIDTH: usize = TAB_REPLACEMENT.len(); // -- Diff background palette -------------------------------------------------- // @@ -989,7 +991,10 @@ fn wrap_styled_spans(spans: &[RtSpan<'static>], max_cols: usize) -> Vec], max_cols: usize) -> Vec= 2, - "tab + 5 chars should exceed 8 cols and wrap, got {} line(s): {result:?}", - result.len() + assert_eq!( + result, + vec![ + vec![RtSpan::styled(" abcd", style)], + vec![RtSpan::styled("e", style)], + ] ); } @@ -2373,7 +2390,7 @@ mod tests { .collect::() }) .collect(); - assert_eq!(line_text, vec!["abcd", "\t", "界"]); + assert_eq!(line_text, vec!["abcd", " ", "界"]); let line_width = |line: &[RtSpan<'static>]| -> usize { line.iter() diff --git a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_120x40.snap b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_120x40.snap index 07985926c47f..8a46e716af73 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_120x40.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_120x40.snap @@ -4,9 +4,9 @@ expression: terminal.backend() --- "• Edited 6 files (+9 -9) " " └ assets/banner.txt (+3 -0) " -" 1 +HEADER VALUE " -" 2 +rocket 🚀 " Hidden by multi-width symbols: [(15, " ")] -" 3 +city 東京 " Hidden by multi-width symbols: [(13, " "), (15, " ")] +" 1 +HEADER VALUE " +" 2 +rocket 🚀 " Hidden by multi-width symbols: [(18, " ")] +" 3 +city 東京 " Hidden by multi-width symbols: [(16, " "), (18, " ")] " " " └ examples/new_sample.rs (+3 -0) " " 1 +pub fn greet(name: &str) { " @@ -20,8 +20,8 @@ expression: terminal.backend() " " " └ scripts/calc.txt → scripts/calc.py (+1 -1) " " 1 def add(a, b): " -" 2 - return a + b " -" 2 + return a + b + 42 " +" 2 - return a + b " +" 2 + return a + b + 42 " " 3 " " 4 print(add(1, 2)) " " " diff --git a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_80x24.snap b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_80x24.snap index b3da476a2df6..f7ba17c1c2fa 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_80x24.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_80x24.snap @@ -4,9 +4,9 @@ expression: terminal.backend() --- "• Edited 6 files (+9 -9) " " └ assets/banner.txt (+3 -0) " -" 1 +HEADER VALUE " -" 2 +rocket 🚀 " Hidden by multi-width symbols: [(15, " ")] -" 3 +city 東京 " Hidden by multi-width symbols: [(13, " "), (15, " ")] +" 1 +HEADER VALUE " +" 2 +rocket 🚀 " Hidden by multi-width symbols: [(18, " ")] +" 3 +city 東京 " Hidden by multi-width symbols: [(16, " "), (18, " ")] " " " └ examples/new_sample.rs (+3 -0) " " 1 +pub fn greet(name: &str) { " @@ -20,8 +20,8 @@ expression: terminal.backend() " " " └ scripts/calc.txt → scripts/calc.py (+1 -1) " " 1 def add(a, b): " -" 2 - return a + b " -" 2 + return a + b + 42 " +" 2 - return a + b " +" 2 + return a + b + 42 " " 3 " " 4 print(add(1, 2)) " " " diff --git a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_94x35.snap b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_94x35.snap index 9eaffa6c91b9..c30d789fe920 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_94x35.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__diff_render__tests__diff_gallery_94x35.snap @@ -4,9 +4,9 @@ expression: terminal.backend() --- "• Edited 6 files (+9 -9) " " └ assets/banner.txt (+3 -0) " -" 1 +HEADER VALUE " -" 2 +rocket 🚀 " Hidden by multi-width symbols: [(15, " ")] -" 3 +city 東京 " Hidden by multi-width symbols: [(13, " "), (15, " ")] +" 1 +HEADER VALUE " +" 2 +rocket 🚀 " Hidden by multi-width symbols: [(18, " ")] +" 3 +city 東京 " Hidden by multi-width symbols: [(16, " "), (18, " ")] " " " └ examples/new_sample.rs (+3 -0) " " 1 +pub fn greet(name: &str) { " @@ -20,8 +20,8 @@ expression: terminal.backend() " " " └ scripts/calc.txt → scripts/calc.py (+1 -1) " " 1 def add(a, b): " -" 2 - return a + b " -" 2 + return a + b + 42 " +" 2 - return a + b " +" 2 + return a + b + 42 " " 3 " " 4 print(add(1, 2)) " " "