diff options
author | Wang Xuerui <git@xen0n.name> | 2019-11-14 11:48:30 +0800 |
---|---|---|
committer | Wang Xuerui <git@xen0n.name> | 2019-11-14 11:48:32 +0800 |
commit | b9ed24d34fa7d69abcc8169441c5649463915013 (patch) | |
tree | 24c1edfed1364ec641ae49942d510c3e0d48a27b /src/edits.rs | |
parent | 0052bd7b170188ec30fd1beb5ed89b51c8efbd70 (diff) |
Properly calculate string widths with unicode_width
Fixes diffs rendering with lines containing CJK characters.
Diffstat (limited to 'src/edits.rs')
-rw-r--r-- | src/edits.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/edits.rs b/src/edits.rs index 615e2181..4482133c 100644 --- a/src/edits.rs +++ b/src/edits.rs @@ -1,6 +1,6 @@ use regex::Regex; -use unicode_segmentation::UnicodeSegmentation; +use unicode_width::UnicodeWidthStr; use crate::align; @@ -152,7 +152,7 @@ where plus_line, ) }; - let distance_contribution = |section: &str| section.trim().graphemes(true).count(); + let distance_contribution = |section: &str| UnicodeWidthStr::width(section.trim()); let (mut minus_op_prev, mut plus_op_prev) = (noop_deletion, noop_insertion); for (op, n) in alignment.coalesced_operations() { |