editor: Newtype WrapRow (#41843)
Makes a better distinction between `WrapRow` and `BlockRow` Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
+44
-41
@@ -9,15 +9,7 @@ pub struct Patch<T>(Vec<Edit<T>>);
|
||||
|
||||
impl<T> Patch<T>
|
||||
where
|
||||
T: 'static
|
||||
+ Clone
|
||||
+ Copy
|
||||
+ Ord
|
||||
+ Sub<T, Output = T>
|
||||
+ Add<T, Output = T>
|
||||
+ AddAssign
|
||||
+ Default
|
||||
+ PartialEq,
|
||||
T: 'static + Clone + Copy + Ord + Default,
|
||||
{
|
||||
pub fn new(edits: Vec<Edit<T>>) -> Self {
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -41,7 +33,50 @@ where
|
||||
pub fn into_inner(self) -> Vec<Edit<T>> {
|
||||
self.0
|
||||
}
|
||||
pub fn invert(&mut self) -> &mut Self {
|
||||
for edit in &mut self.0 {
|
||||
mem::swap(&mut edit.old, &mut edit.new);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.0.clear();
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
pub fn push(&mut self, edit: Edit<T>) {
|
||||
if edit.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(last) = self.0.last_mut() {
|
||||
if last.old.end >= edit.old.start {
|
||||
last.old.end = edit.old.end;
|
||||
last.new.end = edit.new.end;
|
||||
} else {
|
||||
self.0.push(edit);
|
||||
}
|
||||
} else {
|
||||
self.0.push(edit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, TDelta> Patch<T>
|
||||
where
|
||||
T: 'static
|
||||
+ Copy
|
||||
+ Ord
|
||||
+ Sub<T, Output = TDelta>
|
||||
+ Add<TDelta, Output = T>
|
||||
+ AddAssign<TDelta>
|
||||
+ Default,
|
||||
TDelta: Ord + Copy,
|
||||
{
|
||||
#[must_use]
|
||||
pub fn compose(&self, new_edits_iter: impl IntoIterator<Item = Edit<T>>) -> Self {
|
||||
let mut old_edits_iter = self.0.iter().cloned().peekable();
|
||||
@@ -169,38 +204,6 @@ where
|
||||
composed
|
||||
}
|
||||
|
||||
pub fn invert(&mut self) -> &mut Self {
|
||||
for edit in &mut self.0 {
|
||||
mem::swap(&mut edit.old, &mut edit.new);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.0.clear();
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
pub fn push(&mut self, edit: Edit<T>) {
|
||||
if edit.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(last) = self.0.last_mut() {
|
||||
if last.old.end >= edit.old.start {
|
||||
last.old.end = edit.old.end;
|
||||
last.new.end = edit.new.end;
|
||||
} else {
|
||||
self.0.push(edit);
|
||||
}
|
||||
} else {
|
||||
self.0.push(edit);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn old_to_new(&self, old: T) -> T {
|
||||
let ix = match self.0.binary_search_by(|probe| probe.old.start.cmp(&old)) {
|
||||
Ok(ix) => ix,
|
||||
|
||||
Reference in New Issue
Block a user