Skip to content

Commit

Permalink
Always replace tabs, even in single-column display
Browse files Browse the repository at this point in the history
Fixes #617
  • Loading branch information
Wilfred committed Mar 5, 2024
1 parent d095465 commit b78f7d4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sample_files/compare.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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 -

Expand Down
1 change: 1 addition & 0 deletions sample_files/tab_after.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default env;
9 changes: 9 additions & 0 deletions sample_files/tab_before.txt
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 12 additions & 1 deletion src/display/side_by_side.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b78f7d4

Please sign in to comment.