Implement Anchor, AnchorRangeMap, SelectionSet in multi_buffer

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld
2021-12-08 12:56:09 -08:00
co-authored by Nathan Sobo
parent a7634ccd5f
commit daedf179b2
6 changed files with 525 additions and 78 deletions
+3 -4
View File
@@ -1,6 +1,5 @@
use super::{FromAnchor, FullOffset, Point, ToOffset};
use crate::{rope::TextDimension, BufferSnapshot};
use super::{Buffer, FromAnchor, FullOffset, Point, ToOffset};
use anyhow::Result;
use std::{
cmp::Ordering,
@@ -99,7 +98,7 @@ impl Anchor {
Ok(offset_comparison.then_with(|| self.bias.cmp(&other.bias)))
}
pub fn bias_left(&self, buffer: &Buffer) -> Anchor {
pub fn bias_left(&self, buffer: &BufferSnapshot) -> Anchor {
if self.bias == Bias::Left {
self.clone()
} else {
@@ -107,7 +106,7 @@ impl Anchor {
}
}
pub fn bias_right(&self, buffer: &Buffer) -> Anchor {
pub fn bias_right(&self, buffer: &BufferSnapshot) -> Anchor {
if self.bias == Bias::Right {
self.clone()
} else {
+9
View File
@@ -685,6 +685,15 @@ impl sum_tree::Summary for TextSummary {
}
}
impl<'a> std::ops::Add<Self> for TextSummary {
type Output = Self;
fn add(mut self, rhs: Self) -> Self::Output {
self.add_assign(&rhs);
self
}
}
impl<'a> std::ops::AddAssign<&'a Self> for TextSummary {
fn add_assign(&mut self, other: &'a Self) {
let joined_chars = self.last_line_chars + other.first_line_chars;