@@ -1,6 +1,4 @@
3−use crate::{Change, Transaction};
1+use crate::{Rope, Transaction};
5/// Compares `old` and `new` to generate a [`Transaction`] describing
3/// Compares `old` and `new` to generate a [`Transaction`] describing
6/// the steps required to get from `old` to `new`.
4/// the steps required to get from `old` to `new`.
@@ -25,34 +23,34 @@ pub fn compare_ropes(old: &Rope, new: &Rope) -> Transaction {
25 // The current position of the change needs to be tracked to
23 // The current position of the change needs to be tracked to
26 // construct the `Change`s.
24 // construct the `Change`s.
27 let mut pos = 0;
25 let mut pos = 0;
28− let changes: Vec<Change> = diff
26+ Transaction::change(
31− .map(|op| op.as_tag_tuple())
30+ .map(|op| op.as_tag_tuple())
32− .filter_map(|(tag, old_range, new_range)| {
31+ .filter_map(|(tag, old_range, new_range)| {
33− // `old_pos..pos` is equivalent to `start..end` for where
32+ // `old_pos..pos` is equivalent to `start..end` for where
34− // the change should be applied.
33+ // the change should be applied.
35− let old_pos = pos;
34+ let old_pos = pos;
36− pos += old_range.end - old_range.start;
35+ pos += old_range.end - old_range.start;
38− match tag {
37+ match tag {
39− // Semantically, inserts and replacements are the same thing.
38+ // Semantically, inserts and replacements are the same thing.
40− similar::DiffTag::Insert | similar::DiffTag::Replace => {
39+ similar::DiffTag::Insert | similar::DiffTag::Replace => {
41− // This is the text from the `new` rope that should be
40+ // This is the text from the `new` rope that should be
42− // inserted into `old`.
41+ // inserted into `old`.
43− let text: &str = {
42+ let text: &str = {
44− let start = new.char_to_byte(new_range.start);
43+ let start = new.char_to_byte(new_range.start);
45− let end = new.char_to_byte(new_range.end);
44+ let end = new.char_to_byte(new_range.end);
46− &new_converted[start..end]
45+ &new_converted[start..end]
48− Some((old_pos, pos, Some(text.into())))
47+ Some((old_pos, pos, Some(text.into())))
49+ similar::DiffTag::Delete => Some((old_pos, pos, None)),
50+ similar::DiffTag::Equal => None,
50− similar::DiffTag::Delete => Some((old_pos, pos, None)),
51− similar::DiffTag::Equal => None,
55− Transaction::change(old, changes.into_iter())
58#[cfg(test)]
56#[cfg(test)]