on master help sign in
Fix transaction.invert()/.apply() using byte counts instead of char counts.
883b77bBlaž Hrastnik
helix-core/src/transaction.rs+5−4
@@ -211,8 +211,9 @@ impl ChangeSet {
211 pos += n;
211 pos += n;
212 }
212 }
213 Insert(s) => {
213 Insert(s) => {
214+ let chars = s.chars().count();
214− changes.push(Delete(s.len()));
215+ changes.push(Delete(chars));
215− len += s.len();
216+ len += chars;
216 }
217 }
217 }
218 }
218 }
219 }
@@ -240,7 +241,7 @@ impl ChangeSet {
240 }
241 }
241 Insert(s) => {
242 Insert(s) => {
242 text.insert(pos, s);
243 text.insert(pos, s);
243− pos += s.len();
244+ pos += s.chars().count();
244 }
245 }
245 }
246 }
246 }
247 }
@@ -497,7 +498,7 @@ mod test {
497 len: 12,
498 len: 12,
498 };
499 };
499
500
500− let doc = Rope::from("123 hello xz");
501+ let doc = Rope::from("世界3 hello xz");
501 let revert = changes.invert(&doc);
502 let revert = changes.invert(&doc);
502
503
503 let mut doc2 = doc.clone();
504 let mut doc2 = doc.clone();