diff --git a/CHANGELOG.md b/CHANGELOG.md index b8c5025ca9..adb2113e96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ from `git diff`. Fixed an issue with the experimental JSON display mode where it ignored `--skip-unchanged`. +Fixed an issue with tabs not being replaced in single-column display. + ## 0.55 (released 1st February 2024) ### Parsing diff --git a/sample_files/compare.expected b/sample_files/compare.expected index 7d98ca0060..c684e87a20 100644 --- a/sample_files/compare.expected +++ b/sample_files/compare.expected @@ -247,6 +247,9 @@ sample_files/syntax_error_before.js sample_files/syntax_error_after.js sample_files/tab_before.c sample_files/tab_after.c 7e4345e584d440a136f90becb0ef45bc - +sample_files/tab_before.txt sample_files/tab_after.txt +c7fcee21dd5ebd251e2cf4cd7d4446d2 - + sample_files/tailwind_before.css sample_files/tailwind_after.css db01dde1e8455a144e5bf0511273f674 - diff --git a/sample_files/tab_after.txt b/sample_files/tab_after.txt new file mode 100644 index 0000000000..3535611de3 --- /dev/null +++ b/sample_files/tab_after.txt @@ -0,0 +1 @@ +export default env; diff --git a/sample_files/tab_before.txt b/sample_files/tab_before.txt new file mode 100644 index 0000000000..78d87072b1 --- /dev/null +++ b/sample_files/tab_before.txt @@ -0,0 +1,9 @@ +export const ORIGIN = new URL( + env.VERCEL_ENV === "production" + ? "https://alpha.sweets.community" + : env.VERCEL_ENV === "preview" + ? `https://${env.VERCEL_URL}` + : "http://localhost:3000" +); + +export default env; diff --git a/src/display/side_by_side.rs b/src/display/side_by_side.rs index 76c6228552..0b32e1fa6d 100644 --- a/src/display/side_by_side.rs +++ b/src/display/side_by_side.rs @@ -102,7 +102,7 @@ fn display_single_column( .style(style) .to_string(), ); - formatted_line.push_str(&replace_tabs(line, display_options.tab_width)); + formatted_line.push_str(line); formatted_lines.push(formatted_line); } @@ -339,6 +339,17 @@ pub(crate) fn print( ) }; + // Style positions are relative to the source code offsets. Now + // that we've applied styling, we can replace tabs. + let lhs_colored_lines: Vec<_> = lhs_colored_lines + .iter() + .map(|l| replace_tabs(l, display_options.tab_width)) + .collect(); + let rhs_colored_lines: Vec<_> = rhs_colored_lines + .iter() + .map(|l| replace_tabs(l, display_options.tab_width)) + .collect(); + if lhs_src.is_empty() { for line in display_single_column( display_path,