|
|
@ -1,6 +1,4 @@
|
|
|
|
use ropey::Rope;
|
|
|
|
use crate::{Rope, Transaction};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{Change, Transaction};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Compares `old` and `new` to generate a [`Transaction`] describing
|
|
|
|
/// Compares `old` and `new` to generate a [`Transaction`] describing
|
|
|
|
/// the steps required to get from `old` to `new`.
|
|
|
|
/// the steps required to get from `old` to `new`.
|
|
|
@ -25,8 +23,9 @@ pub fn compare_ropes(old: &Rope, new: &Rope) -> Transaction {
|
|
|
|
// The current position of the change needs to be tracked to
|
|
|
|
// The current position of the change needs to be tracked to
|
|
|
|
// construct the `Change`s.
|
|
|
|
// construct the `Change`s.
|
|
|
|
let mut pos = 0;
|
|
|
|
let mut pos = 0;
|
|
|
|
let changes: Vec<Change> = diff
|
|
|
|
Transaction::change(
|
|
|
|
.ops()
|
|
|
|
old,
|
|
|
|
|
|
|
|
diff.ops()
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.map(|op| op.as_tag_tuple())
|
|
|
|
.map(|op| op.as_tag_tuple())
|
|
|
|
.filter_map(|(tag, old_range, new_range)| {
|
|
|
|
.filter_map(|(tag, old_range, new_range)| {
|
|
|
@ -50,9 +49,8 @@ pub fn compare_ropes(old: &Rope, new: &Rope) -> Transaction {
|
|
|
|
similar::DiffTag::Delete => Some((old_pos, pos, None)),
|
|
|
|
similar::DiffTag::Delete => Some((old_pos, pos, None)),
|
|
|
|
similar::DiffTag::Equal => None,
|
|
|
|
similar::DiffTag::Equal => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
.collect();
|
|
|
|
)
|
|
|
|
Transaction::change(old, changes.into_iter())
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|