summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2021-12-03 00:17:20 +0100
committerDan Davison <dandavison7@gmail.com>2021-12-02 20:33:35 -0500
commitc8aa15d3515a123b0c5a89baf3ff674d81b04d73 (patch)
tree0a9d39c655e4408281d400649148f781bf9bdb34
parent75eaf90a44c6e4c621cd5ccd8f796496bb74de1b (diff)
Fix side-by-side line number miscount
-rw-r--r--src/features/line_numbers.rs28
-rw-r--r--src/features/side_by_side.rs8
2 files changed, 36 insertions, 0 deletions
diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs
index 7082d05d..0d366f8a 100644
--- a/src/features/line_numbers.rs
+++ b/src/features/line_numbers.rs
@@ -773,6 +773,25 @@ pub mod tests {
assert_eq!(lines.next().unwrap(), " ⋮500 │bb = 4");
}
+ #[test]
+ fn test_line_numbers_continue_correctly() {
+ let config = make_config_from_args(&[
+ "--side-by-side",
+ "--width",
+ "40",
+ "--line-fill-method=spaces",
+ ]);
+
+ let output = run_delta(HUNK_PLUS_MINUS_WITH_1_CONTEXT_DIFF, &config);
+ let mut lines = output.lines().skip(crate::config::HEADER_LEN);
+
+ // closure to help with `cargo fmt`-ing:
+ let mut next_line = || strip_ansi_codes(lines.next().unwrap());
+ assert_eq!("│ 1 │same │ 1 │same", next_line());
+ assert_eq!("│ 2 │a = left │ 2 │a = right ", next_line());
+ assert_eq!("│ 3 │also same │ 3 │also same", next_line());
+ }
+
pub const TWO_MINUS_LINES_DIFF: &str = "\
diff --git i/a.py w/a.py
index 223ca50..e69de29 100644
@@ -841,4 +860,13 @@ index 223ca50..367a6f6 100644
-b = 2
+bb = 2
";
+
+ const HUNK_PLUS_MINUS_WITH_1_CONTEXT_DIFF: &str = "\
+--- a/a.py
++++ b/b.py
+@@ -1,3 +1,3 @@
+ same
+-a = left
++a = right
+ also same";
}
diff --git a/src/features/side_by_side.rs b/src/features/side_by_side.rs
index 4f02c47c..f4960d76 100644
--- a/src/features/side_by_side.rs
+++ b/src/features/side_by_side.rs
@@ -186,6 +186,14 @@ pub fn paint_minus_and_plus_lines_side_by_side(
bg_should_fill[Left],
config,
));
+
+ // HACK: The left line number is not getting incremented in `linenumbers_and_styles()`
+ // when the alignment matches a minus with a plus line, so fix that here.
+ // This information should be passed down into `paint_line()` to set `increment` to true.
+ if minus_line_index.is_some() && plus_line_index.is_some() {
+ line_numbers_data.line_number[Left] += 1;
+ }
+
output_buffer.push_str(&paint_right_panel_plus_line(
plus_line_index,
&syntax_sections[Right],