aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/transaction.rs
diff options
context:
space:
mode:
authorKirawi2021-06-05 03:49:19 +0000
committerGitHub2021-06-05 03:49:19 +0000
commitc17dcb8633550a4efde56ca5b4e2b00fbf9f45e1 (patch)
tree9ab71f76679c1735f275448768c091219e2d49c0 /helix-core/src/transaction.rs
parent5a344a3ae508f571ad5427e14ffad683213bf142 (diff)
Fixing Multiple Panics (#121)
* init * wip * wip
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());
+ }
}