Remove result from anchor cmp functions
Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
ab631cf6c3
commit
92c7b5d6ef
11 changed files with 68 additions and 141 deletions
|
@ -522,24 +522,14 @@ impl MultiBuffer {
|
|||
self.buffers.borrow()[&buffer_id]
|
||||
.buffer
|
||||
.update(cx, |buffer, cx| {
|
||||
selections.sort_unstable_by(|a, b| a.start.cmp(&b.start, buffer).unwrap());
|
||||
selections.sort_unstable_by(|a, b| a.start.cmp(&b.start, buffer));
|
||||
let mut selections = selections.into_iter().peekable();
|
||||
let merged_selections = Arc::from_iter(iter::from_fn(|| {
|
||||
let mut selection = selections.next()?;
|
||||
while let Some(next_selection) = selections.peek() {
|
||||
if selection
|
||||
.end
|
||||
.cmp(&next_selection.start, buffer)
|
||||
.unwrap()
|
||||
.is_ge()
|
||||
{
|
||||
if selection.end.cmp(&next_selection.start, buffer).is_ge() {
|
||||
let next_selection = selections.next().unwrap();
|
||||
if next_selection
|
||||
.end
|
||||
.cmp(&selection.end, buffer)
|
||||
.unwrap()
|
||||
.is_ge()
|
||||
{
|
||||
if next_selection.end.cmp(&selection.end, buffer).is_ge() {
|
||||
selection.end = next_selection.end;
|
||||
}
|
||||
} else {
|
||||
|
@ -1936,11 +1926,7 @@ impl MultiBufferSnapshot {
|
|||
.range
|
||||
.start
|
||||
.bias(anchor.text_anchor.bias, &excerpt.buffer);
|
||||
if text_anchor
|
||||
.cmp(&excerpt.range.end, &excerpt.buffer)
|
||||
.unwrap()
|
||||
.is_gt()
|
||||
{
|
||||
if text_anchor.cmp(&excerpt.range.end, &excerpt.buffer).is_gt() {
|
||||
text_anchor = excerpt.range.end.clone();
|
||||
}
|
||||
Anchor {
|
||||
|
@ -1955,7 +1941,6 @@ impl MultiBufferSnapshot {
|
|||
.bias(anchor.text_anchor.bias, &excerpt.buffer);
|
||||
if text_anchor
|
||||
.cmp(&excerpt.range.start, &excerpt.buffer)
|
||||
.unwrap()
|
||||
.is_lt()
|
||||
{
|
||||
text_anchor = excerpt.range.start.clone();
|
||||
|
@ -1975,7 +1960,7 @@ impl MultiBufferSnapshot {
|
|||
result.push((anchor_ix, anchor, kept_position));
|
||||
}
|
||||
}
|
||||
result.sort_unstable_by(|a, b| a.1.cmp(&b.1, self).unwrap());
|
||||
result.sort_unstable_by(|a, b| a.1.cmp(&b.1, self));
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -2322,10 +2307,10 @@ impl MultiBufferSnapshot {
|
|||
excerpt_id: excerpt.id.clone(),
|
||||
text_anchor: selection.end.clone(),
|
||||
};
|
||||
if range.start.cmp(&start, self).unwrap().is_gt() {
|
||||
if range.start.cmp(&start, self).is_gt() {
|
||||
start = range.start.clone();
|
||||
}
|
||||
if range.end.cmp(&end, self).unwrap().is_lt() {
|
||||
if range.end.cmp(&end, self).is_lt() {
|
||||
end = range.end.clone();
|
||||
}
|
||||
|
||||
|
@ -2549,17 +2534,9 @@ impl Excerpt {
|
|||
}
|
||||
|
||||
fn clip_anchor(&self, text_anchor: text::Anchor) -> text::Anchor {
|
||||
if text_anchor
|
||||
.cmp(&self.range.start, &self.buffer)
|
||||
.unwrap()
|
||||
.is_lt()
|
||||
{
|
||||
if text_anchor.cmp(&self.range.start, &self.buffer).is_lt() {
|
||||
self.range.start.clone()
|
||||
} else if text_anchor
|
||||
.cmp(&self.range.end, &self.buffer)
|
||||
.unwrap()
|
||||
.is_gt()
|
||||
{
|
||||
} else if text_anchor.cmp(&self.range.end, &self.buffer).is_gt() {
|
||||
self.range.end.clone()
|
||||
} else {
|
||||
text_anchor
|
||||
|
@ -2572,13 +2549,11 @@ impl Excerpt {
|
|||
.range
|
||||
.start
|
||||
.cmp(&anchor.text_anchor, &self.buffer)
|
||||
.unwrap()
|
||||
.is_le()
|
||||
&& self
|
||||
.range
|
||||
.end
|
||||
.cmp(&anchor.text_anchor, &self.buffer)
|
||||
.unwrap()
|
||||
.is_ge()
|
||||
}
|
||||
}
|
||||
|
@ -3385,7 +3360,7 @@ mod tests {
|
|||
let bias = if rng.gen() { Bias::Left } else { Bias::Right };
|
||||
log::info!("Creating anchor at {} with bias {:?}", offset, bias);
|
||||
anchors.push(multibuffer.anchor_at(offset, bias));
|
||||
anchors.sort_by(|a, b| a.cmp(&b, &multibuffer).unwrap());
|
||||
anchors.sort_by(|a, b| a.cmp(&b, &multibuffer));
|
||||
}
|
||||
40..=44 if !anchors.is_empty() => {
|
||||
let multibuffer = multibuffer.read(cx).read(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue