diff --git a/src/config.rs b/src/config.rs index c795b7f70..9fc757d3f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,6 +14,7 @@ pub struct Config<'a> { pub theme: Option<&'a Theme>, pub theme_name: String, pub max_line_distance: f64, + pub max_line_distance_for_naively_paired_lines: f64, pub minus_style_modifier: StyleModifier, pub minus_emph_style_modifier: StyleModifier, pub plus_style_modifier: StyleModifier, @@ -130,10 +131,16 @@ pub fn get_config<'a>( let minus_line_marker = if keep_plus_minus_markers { "-" } else { " " }; let plus_line_marker = if keep_plus_minus_markers { "+" } else { " " }; + let max_line_distance_for_naively_paired_lines = + env::get_env_var("DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINES") + .map(|s| s.parse::().unwrap_or(0.0)) + .unwrap_or(0.0); + Config { theme, theme_name, max_line_distance: opt.max_line_distance, + max_line_distance_for_naively_paired_lines, minus_style_modifier, minus_emph_style_modifier, plus_style_modifier, diff --git a/src/edits.rs b/src/edits.rs index 84b210c10..1788afd51 100644 --- a/src/edits.rs +++ b/src/edits.rs @@ -16,6 +16,7 @@ pub fn infer_edits<'a, EditOperation>( noop_insertion: EditOperation, insertion: EditOperation, max_line_distance: f64, + max_line_distance_for_naively_paired_lines: f64, ) -> ( Vec>, // annotated minus lines Vec>, // annotated plus lines @@ -42,7 +43,10 @@ where minus_line, plus_line, ); - if distance <= max_line_distance { + if minus_lines.len() == plus_lines.len() + && distance <= max_line_distance_for_naively_paired_lines + || distance <= max_line_distance + { // minus_line and plus_line are inferred to be a homologous pair. // Emit as unpaired the plus lines already considered and rejected @@ -597,6 +601,7 @@ mod tests { PlusNoop, Insertion, max_line_distance, + 0.0, ); assert_eq!(actual_edits, expected_edits); } diff --git a/src/paint.rs b/src/paint.rs index a82ecc4a3..9f220ae09 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -219,6 +219,7 @@ impl<'a> Painter<'a> { config.plus_style_modifier, config.plus_emph_style_modifier, config.max_line_distance, + config.max_line_distance_for_naively_paired_lines, ) } }