Fix crash when opposite side has unpaired lines

See #66
pull/78/head
Wilfred Hughes 2021-12-18 23:30:16 +07:00
parent 06ad384243
commit 382d498559
2 changed files with 36 additions and 18 deletions

@ -7,6 +7,9 @@ variable DFT_WIDTH.
Fixed terminal width calculations on Windows.
Fixed crash when only one side has changes, but the other side has
additional blank lines.
Fixed crash on displaying unicode characters on line boundaries.
### Build

@ -262,10 +262,10 @@ pub fn display_hunks(
);
if no_lhs_changes {
let rhs_line = &rhs_colored_lines[rhs_line_num.expect("Should have RHS line").0];
match rhs_line_num {
Some(rhs_line_num) => {
let rhs_line = &rhs_colored_lines[rhs_line_num.0];
if same_lines {
// Don't print the line numbers in two columns if
// they're all the same.
out_lines.push(format!("{}{}", display_rhs_line_num, rhs_line));
} else {
out_lines.push(format!(
@ -273,8 +273,18 @@ pub fn display_hunks(
display_lhs_line_num, display_rhs_line_num, rhs_line
));
}
}
None => {
// We didn't have any changed RHS lines in the
// hunk, but we had some contextual lines that
// only occurred on the LHS (e.g. extra newlines).
out_lines.push(format!("{}{}", display_rhs_line_num, display_rhs_line_num));
}
}
} else if no_rhs_changes {
let lhs_line = &lhs_colored_lines[lhs_line_num.expect("Should have LHS line").0];
match lhs_line_num {
Some(lhs_line_num) => {
let lhs_line = &lhs_colored_lines[lhs_line_num.0];
if same_lines {
out_lines.push(format!("{}{}", display_lhs_line_num, lhs_line));
} else {
@ -283,6 +293,11 @@ pub fn display_hunks(
display_lhs_line_num, display_rhs_line_num, lhs_line
));
}
}
None => {
out_lines.push(format!("{}{}", display_lhs_line_num, display_rhs_line_num));
}
}
} else {
let lhs_line = match lhs_line_num {
Some(lhs_line_num) => split_and_apply(