summaryrefslogtreecommitdiff
path: root/helix-core/src/transaction.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src/transaction.rs')
-rw-r--r--helix-core/src/transaction.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index e61063f0..085f40b7 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -90,7 +90,8 @@ impl ChangeSet {
return;
}
- self.len_after += fragment.len();
+ // Avoiding std::str::len() to account for UTF-8 characters.
+ self.len_after += fragment.chars().count();
let new_last = match self.changes.as_mut_slice() {
[.., Insert(prev)] | [.., Insert(prev), Delete(_)] => {
@@ -754,4 +755,21 @@ mod test {
use Operation::*;
assert_eq!(changes.changes, &[Insert("a".into())]);
}
+
+ #[test]
+ fn combine_with_utf8() {
+ const TEST_CASE: &'static str = "Hello, これはヒレクスエディターです!";
+
+ let empty = Rope::from("");
+ let mut a = ChangeSet::new(&empty);
+
+ let mut b = ChangeSet::new(&empty);
+ b.insert(TEST_CASE.into());
+
+ let changes = a.compose(b);
+
+ use Operation::*;
+ assert_eq!(changes.changes, &[Insert(TEST_CASE.into())]);
+ assert_eq!(changes.len_after, TEST_CASE.chars().count());
+ }
}