mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-28 01:26:48 +00:00
WIP
This commit is contained in:
parent
7bc4cb9868
commit
dd2bb8dac6
5 changed files with 148 additions and 4 deletions
|
@ -660,6 +660,28 @@ impl DisplaySnapshot {
|
|||
new_start..new_end
|
||||
}
|
||||
|
||||
pub fn clip_buffer_points(
|
||||
&self,
|
||||
points: impl IntoIterator<Item = (MultiBufferPoint, Bias)>,
|
||||
) -> impl Iterator<Item = MultiBufferPoint> {
|
||||
let block_points = self.block_snapshot.to_block_points(
|
||||
self.wrap_snapshot.to_wrap_points(
|
||||
self.tab_snapshot.to_tab_points(
|
||||
self.fold_snapshot
|
||||
.to_fold_points(self.inlay_snapshot.to_inlay_points(points)),
|
||||
),
|
||||
),
|
||||
);
|
||||
self.inlay_snapshot.to_buffer_points(
|
||||
self.fold_snapshot.to_inlay_points(
|
||||
self.tab_snapshot.to_fold_points(
|
||||
self.wrap_snapshot
|
||||
.to_tab_points(self.block_snapshot.to_wrap_points(block_points)),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn point_to_display_point(&self, point: MultiBufferPoint, bias: Bias) -> DisplayPoint {
|
||||
let inlay_point = self.inlay_snapshot.to_inlay_point(point);
|
||||
let fold_point = self.fold_snapshot.to_fold_point(inlay_point, bias);
|
||||
|
|
|
@ -79,10 +79,7 @@ impl FoldPoint {
|
|||
}
|
||||
|
||||
pub fn to_inlay_point(self, snapshot: &FoldSnapshot) -> InlayPoint {
|
||||
let mut cursor = snapshot.transforms.cursor::<(FoldPoint, InlayPoint)>(&());
|
||||
cursor.seek(&self, Bias::Right, &());
|
||||
let overshoot = self.0 - cursor.start().0 .0;
|
||||
InlayPoint(cursor.start().1 .0 + overshoot)
|
||||
snapshot.to_inlay_point(self)
|
||||
}
|
||||
|
||||
pub fn to_offset(self, snapshot: &FoldSnapshot) -> FoldOffset {
|
||||
|
@ -618,6 +615,48 @@ impl FoldSnapshot {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_fold_points<'a>(
|
||||
&'a self,
|
||||
points: impl 'a + IntoIterator<Item = (InlayPoint, Bias)>,
|
||||
) -> impl 'a + Iterator<Item = FoldPoint> {
|
||||
let mut cursor = self.transforms.cursor::<(InlayPoint, FoldPoint)>(&());
|
||||
points.into_iter().map(move |(point, bias)| {
|
||||
cursor.seek_forward(&point, Bias::Right, &());
|
||||
if cursor.item().map_or(false, |t| t.is_fold()) {
|
||||
if bias == Bias::Left || point == cursor.start().0 {
|
||||
cursor.start().1
|
||||
} else {
|
||||
cursor.end(&()).1
|
||||
}
|
||||
} else {
|
||||
let overshoot = point.0 - cursor.start().0 .0;
|
||||
FoldPoint(cmp::min(
|
||||
cursor.start().1 .0 + overshoot,
|
||||
cursor.end(&()).1 .0,
|
||||
))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn to_inlay_point(&self, point: FoldPoint) -> InlayPoint {
|
||||
let mut cursor = self.transforms.cursor::<(FoldPoint, InlayPoint)>(&());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
let overshoot = point.0 - cursor.start().0 .0;
|
||||
InlayPoint(cursor.start().1 .0 + overshoot)
|
||||
}
|
||||
|
||||
pub fn to_inlay_points<'a>(
|
||||
&'a self,
|
||||
points: impl 'a + IntoIterator<Item = FoldPoint>,
|
||||
) -> impl 'a + Iterator<Item = InlayPoint> {
|
||||
let mut cursor = self.transforms.cursor::<(FoldPoint, InlayPoint)>(&());
|
||||
points.into_iter().map(move |point| {
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
let overshoot = point.0 - cursor.start().0 .0;
|
||||
InlayPoint(cursor.start().1 .0 + overshoot)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn len(&self) -> FoldOffset {
|
||||
FoldOffset(self.transforms.summary().output.len)
|
||||
}
|
||||
|
|
|
@ -789,6 +789,25 @@ impl InlaySnapshot {
|
|||
None => self.buffer.max_point(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_buffer_points<'a>(
|
||||
&'a self,
|
||||
points: impl 'a + IntoIterator<Item = InlayPoint>,
|
||||
) -> impl 'a + Iterator<Item = Point> {
|
||||
let mut cursor = self.transforms.cursor::<(InlayPoint, Point)>(&());
|
||||
points.into_iter().map(move |point| {
|
||||
cursor.seek_forward(&point, Bias::Right, &());
|
||||
match cursor.item() {
|
||||
Some(Transform::Isomorphic(_)) => {
|
||||
let overshoot = point.0 - cursor.start().0 .0;
|
||||
cursor.start().1 + overshoot
|
||||
}
|
||||
Some(Transform::Inlay(_)) => cursor.start().1,
|
||||
None => self.buffer.max_point(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn to_buffer_offset(&self, offset: InlayOffset) -> usize {
|
||||
let mut cursor = self.transforms.cursor::<(InlayOffset, usize)>(&());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
|
@ -835,6 +854,7 @@ impl InlaySnapshot {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_inlay_point(&self, point: Point) -> InlayPoint {
|
||||
let mut cursor = self.transforms.cursor::<(Point, InlayPoint)>(&());
|
||||
cursor.seek(&point, Bias::Left, &());
|
||||
|
@ -869,6 +889,45 @@ impl InlaySnapshot {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_inlay_points<'a>(
|
||||
&'a self,
|
||||
points: impl 'a + IntoIterator<Item = Point>,
|
||||
) -> impl 'a + Iterator<Item = InlayPoint> {
|
||||
let mut cursor = self.transforms.cursor::<(Point, InlayPoint)>(&());
|
||||
points.into_iter().map(move |point| {
|
||||
cursor.seek_forward(&point, Bias::Left, &());
|
||||
loop {
|
||||
match cursor.item() {
|
||||
Some(Transform::Isomorphic(_)) => {
|
||||
if point == cursor.end(&()).0 {
|
||||
while let Some(Transform::Inlay(inlay)) = cursor.next_item() {
|
||||
if inlay.position.bias() == Bias::Right {
|
||||
break;
|
||||
} else {
|
||||
cursor.next(&());
|
||||
}
|
||||
}
|
||||
return cursor.end(&()).1;
|
||||
} else {
|
||||
let overshoot = point - cursor.start().0;
|
||||
return InlayPoint(cursor.start().1 .0 + overshoot);
|
||||
}
|
||||
}
|
||||
Some(Transform::Inlay(inlay)) => {
|
||||
if inlay.position.bias() == Bias::Left {
|
||||
cursor.next(&());
|
||||
} else {
|
||||
return cursor.start().1;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return self.max_point();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn clip_point(&self, mut point: InlayPoint, mut bias: Bias) -> InlayPoint {
|
||||
let mut cursor = self.transforms.cursor::<(InlayPoint, Point)>(&());
|
||||
cursor.seek(&point, Bias::Left, &());
|
||||
|
|
|
@ -304,6 +304,14 @@ impl TabSnapshot {
|
|||
TabPoint::new(input.row(), expanded)
|
||||
}
|
||||
|
||||
pub fn to_tab_points<'a>(
|
||||
&'a self,
|
||||
points: impl 'a + IntoIterator<Item = FoldPoint>,
|
||||
) -> impl 'a + Iterator<Item = TabPoint> {
|
||||
// todo!("make this efficient")
|
||||
points.into_iter().map(|point| self.to_tab_point(point))
|
||||
}
|
||||
|
||||
pub fn to_fold_point(&self, output: TabPoint, bias: Bias) -> (FoldPoint, u32, u32) {
|
||||
let chars = self.fold_snapshot.chars_at(FoldPoint::new(output.row(), 0));
|
||||
let expanded = output.column();
|
||||
|
@ -316,6 +324,16 @@ impl TabSnapshot {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn to_fold_points<'a>(
|
||||
&'a self,
|
||||
points: impl 'a + IntoIterator<Item = (TabPoint, Bias)>,
|
||||
) -> impl 'a + Iterator<Item = FoldPoint> {
|
||||
// todo!("make this efficient")
|
||||
points
|
||||
.into_iter()
|
||||
.map(|(point, bias)| self.to_fold_point(point, bias).0)
|
||||
}
|
||||
|
||||
pub fn make_tab_point(&self, point: Point, bias: Bias) -> TabPoint {
|
||||
let inlay_point = self.fold_snapshot.inlay_snapshot.to_inlay_point(point);
|
||||
let fold_point = self.fold_snapshot.to_fold_point(inlay_point, bias);
|
||||
|
|
|
@ -761,6 +761,12 @@ impl WrapSnapshot {
|
|||
WrapPoint(cursor.start().1 .0 + (point.0 - cursor.start().0 .0))
|
||||
}
|
||||
|
||||
pub fn tab_points_to_wrap_points(
|
||||
&self,
|
||||
points: impl IntoIterator<Item = TabPoint>,
|
||||
) -> impl Iterator<Item = WrapPoint> {
|
||||
}
|
||||
|
||||
pub fn clip_point(&self, mut point: WrapPoint, bias: Bias) -> WrapPoint {
|
||||
if bias == Bias::Left {
|
||||
let mut cursor = self.transforms.cursor::<WrapPoint>(&());
|
||||
|
|
Loading…
Reference in a new issue