Skip to content

Commit

Permalink
Fixed line number painting (dandavison#247)
Browse files Browse the repository at this point in the history
Fixed the painting of line numbers so that instead of each column or
side always keeping the same colour, which looks odd, it instead uses
the colour appropriate to the line's status.

In other words, if there has been a line removed, instead of showing
the left (minus) column/side as minus style and the right (plus)
column/side as plus style, both will be shown as minus style.
  • Loading branch information
danwilliams committed Nov 5, 2023
1 parent 7375f7a commit d34dee9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/features/line_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn linenumbers_and_styles<'a>(
let ((minus_number, plus_number), (minus_style, plus_style)) = match state {
State::HunkMinus(_, _) => {
line_numbers_data.line_number[Left] += increment as usize;
((Some(nr_left), None), (minus_style, plus_style))
((Some(nr_left), None), (minus_style, minus_style))
}
State::HunkMinusWrapped => ((None, None), (minus_style, plus_style)),
State::HunkZero(_, _) => {
Expand All @@ -90,7 +90,7 @@ pub fn linenumbers_and_styles<'a>(
State::HunkZeroWrapped => ((None, None), (zero_style, zero_style)),
State::HunkPlus(_, _) => {
line_numbers_data.line_number[Right] += increment as usize;
((None, Some(nr_right)), (minus_style, plus_style))
((None, Some(nr_right)), (plus_style, plus_style))
}
State::HunkPlusWrapped => ((None, None), (minus_style, plus_style)),
_ => return None,
Expand Down
8 changes: 4 additions & 4 deletions src/features/side_by_side.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ pub mod tests {
.explain_ansi()
.with_input(TWO_PLUS_LINES_DIFF)
.expect_after_header(r#"
(blue)│(88) (blue)│(normal) (blue)│(28) 1 (blue)│(231 22)a (203)=(231) (141)1(normal 22) (normal)
(blue)│(88) (blue)│(normal) (blue)│(28) 2 (blue)│(231 22)b (203)=(231) (141)234567(normal 22) (normal)"#);
(blue)│(28) (blue)│(normal) (blue)│(28) 1 (blue)│(231 22)a (203)=(231) (141)1(normal 22) (normal)
(blue)│(28) (blue)│(normal) (blue)│(28) 2 (blue)│(231 22)b (203)=(231) (141)234567(normal 22) (normal)"#);

DeltaTest::with_args(&[
"--side-by-side",
Expand All @@ -663,8 +663,8 @@ pub mod tests {
.explain_ansi()
.with_input(TWO_PLUS_LINES_DIFF)
.expect_after_header(r#"
(blue)│(88) (blue)│(normal) (blue) │(28) 1 (blue)│(231 22)a (203)=(231) (141)1(normal)
(blue)│(88) (blue)│(normal) (blue) │(28) 2 (blue)│(231 22)b (203)=(231) (141)234567(normal)"#);
(blue)│(28) (blue)│(normal) (blue) │(28) 1 (blue)│(231 22)a (203)=(231) (141)1(normal)
(blue)│(28) (blue)│(normal) (blue) │(28) 2 (blue)│(231 22)b (203)=(231) (141)234567(normal)"#);
}

#[test]
Expand Down

0 comments on commit d34dee9

Please sign in to comment.