From b83cee3707159c4b6bc0c5070a84d78f73017578 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Fri, 26 Jun 2020 14:52:55 -0400 Subject: Bugfix: change op-coalescing algorithm when inferring edits (No test coverage) --- src/edits.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/edits.rs b/src/edits.rs index 9b433ff5..b5ac232e 100644 --- a/src/edits.rs +++ b/src/edits.rs @@ -124,6 +124,7 @@ fn annotate<'a, Annotation>( ) -> (Vec<(Annotation, &'a str)>, Vec<(Annotation, &'a str)>, f64) where Annotation: Copy, + Annotation: PartialEq, { let mut annotated_minus_line = Vec::new(); let mut annotated_plus_line = Vec::new(); @@ -188,8 +189,11 @@ where let n_d = distance_contribution(minus_section); d_denom += n_d; let is_space = minus_section.trim().is_empty(); + let coalesce_space_with_previous = is_space + && ((minus_op_prev == deletion && plus_op_prev == insertion) + || (minus_op_prev == noop_deletion && plus_op_prev == noop_insertion)); annotated_minus_line.push(( - if is_space { + if coalesce_space_with_previous { minus_op_prev } else { noop_deletion @@ -197,7 +201,7 @@ where minus_section, )); annotated_plus_line.push(( - if is_space { + if coalesce_space_with_previous { plus_op_prev } else { noop_insertion -- cgit v1.2.3