on master help sign in
Fix transaction.invert()/.apply() using byte counts instead of char counts.
commit883b77bd246433ab221f16ee7be53ced9beb7c29 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 4 Oct 2020, 17:16 (6 years ago) parent197651e
1 file changed+5−4
helix-core/src/transaction.rs+5−4
helix-core/src/transaction.rs+5−4
@@ -211,8 +211,9 @@ impl ChangeSet {
211211 pos += n;
212212 }
213213 Insert(s) => {
214− changes.push(Delete(s.len()));
215− len += s.len();
214+ let chars = s.chars().count();
215+ changes.push(Delete(chars));
216+ len += chars;
216217 }
217218 }
218219 }
@@ -240,7 +241,7 @@ impl ChangeSet {
240241 }
241242 Insert(s) => {
242243 text.insert(pos, s);
243− pos += s.len();
244+ pos += s.chars().count();
244245 }
245246 }
246247 }
@@ -497,7 +498,7 @@ mod test {
497498 len: 12,
498499 };
499500
500− let doc = Rope::from("123 hello xz");
501+ let doc = Rope::from("世界3 hello xz");
501502 let revert = changes.invert(&doc);
502503
503504 let mut doc2 = doc.clone();